-1

I have a string with this data:

mystring_json = "[{"id":"a373e3e15bac1eeb001785b40a219d","dataInserimento":"2016-09-15 09:30:14","dataPubblicazione":"2016-09-15 09:29:00"},{"id":"4b2444b7b737c8d64e7d60c6515217","dataInserimento":"2016-09-15 08:32:04","dataPubblicazione":"2016-09-15 08:28:00"}...]";

I have a class Poi:

public class Poi {
    public String id;
    private String dataInserimento;
    private String dataPubblicazione;
}

I create a 'Poi' list:

List<Poi> ppp = new ArrayList<>();

I have to put my_string_json data to 'ppp' list.

How can i do this? I'm sorry for my english.

7
  • Are You asking for json parsing Commented Sep 15, 2016 at 11:07
  • 2
    you have to parse either manually or using gson Commented Sep 15, 2016 at 11:09
  • @Donato Micele plz try this ref: androidhive.info/2014/06/… Commented Sep 15, 2016 at 11:11
  • Before Parsing Remove " refer -stackoverflow.com/questions/4503656/…. Then Parse Your data Commented Sep 15, 2016 at 11:12
  • just search any json parsing tutorial for android simple Commented Sep 15, 2016 at 11:14

4 Answers 4

2

Posting an answer because I don't have enough reputation to leave a comment.

You can use gson library, so in order to parse you should do the following:

First, create the following class:

public class ArticleContainer {
    private List<Poi> lstPoi;
}

Then:

Gson gson = new Gson();
PoiResponse poiResponse = gson.fromJson(myString_json, PoiResponse.class);
List<Poi> ppp = poiResponse.getPoi();

In order to compile you need to add this line to your module's build.gradle file:

compile 'com.google.code.gson:gson:2.3.1'

For more information gson README and Related topic

Sign up to request clarification or add additional context in comments.

Comments

1

If you wanna learn JSON Parsing refer this

Parse mystring_json and with the help of either handler class you can add it to your list.

Comments

1

You can try something like this

try{
JSONArray arr = new JSONArray(mystring_json);
List<Poi> ppp = new Arraylist<>();
for(int i=0;i<arr.length();i++){
Poi objj= new Poi();
JSONObject jObj= arr.getJSONObject(i);
objj.setId(jObj.getString("id"));
.
.
.

// at last add 
ppp.add(objj);
}
}Catch(JSONException e){
e.printstacktrace();
}

Comments

1

just add

compile 'com.google.code.gson:gson:2.4'

in your dependency section of app.gradle file. And after that, at the time of parsing

Gson gson = new Gson();
PoiResponse obj = gson.fromJson(data, PoiResponse.class);
List<Poi> ppp = obj.mystring_json;

You have to create one more class, like

public class PoiResponse {
  public ArrayList<Poi> mystring_json;
}

above data is your String response from server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.