How popular is a JSonObject in hand?

0

I'm trying but not right, I wanted to put it in the created hand, as if I had already received my JSON file. I tried to put the JSON structure inside the JSonObject but it did not work.

    
asked by anonymous 16.06.2015 / 20:42

1 answer

0

If you pass your String in JSON format to your JSONObject object, you can do something like this:

try {
    String stringJSON = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
    JSONObject obj = new JSONObject(stringJSON);
    List<String> list = new ArrayList<String>();
    JSONArray array = obj.getJSONArray("interests");
    for (int i = 0; i < array.length(); i++) {
        list.add(array.getJSONObject(i).getString("interestKey"));
    }
} catch (JSONException e) {
    e.printStackTrace();
}

Source: Parsing JSON Object in Java

    
16.06.2015 / 20:53