android-如何使用Gson解析JSON对象内的多个JSON数组?

这个问题已经在这里有了答案:            >            Parse JSON file using GSON                                    3个
如何使用Gson解析JSON对象内的多个JSON数组?

{
    "id": 1,
    "Data": {
        "Details": [{
            "Code": "1",
            "Name": "John"
        }, {
            "Code": "2",
            "Name": "Peter"
        }],
        "Other": [{
            "age": "56",
            "gender": "M"
        }, {
            "age": "66",
            "gender": "M"
        }]
    },
    "message": "SUCCESS"
}

任何帮助,将不胜感激.

解决方法:

简单!

JSONObject jsonObj = new JSONObject(yourStringHere).optJSONObject("Data");
JSONArray jsonDetail = jsonObj.optJSONArray("Details");
JSONArray jsonOther = jsonObj.optJSONArray("Other");
上一篇:JSON对象的Java表示


下一篇:java-如何使Lombok Gson与Spring AOP代理一起使用