0

如何将此字符串转换为 JSONArray ?

{"result":{"passion":[{"id":2,"description":"Sushi"},{"id":3,"description":"Dinner"},{"id":4,"description":"Sex"},{"id":5,"description":"Boobies"},{"id":6,"description":"Sleep"},{"id":7,"description":"Cars"},{"id":8,"description":"Travel"},{"id":9,"description":"Soccer"},{"id":10,"description":"Silice"}]}}

我正在尝试做:

 JSONArray jsonArray = jsonObject.getJSONArray("passion");

但我遇到了一个例外:

org.json.JSONException: No value for passion
4

3 回答 3

2

好像你没有得到result 对象

JSONArray jsonArray = jsonObject. getJSONObject("result").getJSONArray("passion");
于 2013-10-31T12:48:45.777 回答
1

可能这就是你需要的,亲爱的

ArrayList<String> stringArray = new ArrayList<String>();
JSONArray jsonArray = new JSONArray();
for(int i = 0, count = jsonArray.length(); i< count; i++)
{
    try {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        stringArray.add(jsonObject.toString());
    }
    catch (JSONException e) {
        e.printStackTrace();
    }
}
于 2013-10-31T12:46:04.770 回答
0

使用此代码

 JSONObject jsonObject = new JSONObject(json);
 JSONObject resultValues = jsonObject.getJSONObject("result"); 
 JSONArray passionArray = resultValues.getJSONArray("passion")
于 2013-10-31T13:01:56.413 回答