Parsing json objects in java
I have a json object as follows
member = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
In java i want to parse the above json object and store the values in an arraylist
I'm trying to find some code to accomplish this
Best Answer
I'm guessing you want to store the interest keys in a list
Using the org.json library.
JSONObject obj = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");
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"));
}