I have JSON object as follows:
member = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
在Java中,我想解析上面的json对象,并将值存储在arraylist中.
我正在寻找一些代码,通过它我可以实现这一点.
I have JSON object as follows:
member = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
在Java中,我想解析上面的json对象,并将值存储在arraylist中.
我正在寻找一些代码,通过它我可以实现这一点.
我假设您想要将InterestKey存储在列表中.
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"));
}