我需要帮助来解析这个JSON,我有一些问题。
Json to Parse示例1:
{
"object_name_1":{
"id":0,
"value_1":"hello",
"value_2":"test",
},
"object_name_2":{
"id":1,
"value_1":"hello",
"value_2":"test",
},"object_name_3":{
"id":2,
"value_1":"hello",
"value_2":"test",
}
}
Json to Parse示例2:
{
"test_object":{
"id":0,
"value_1":"hello",
"value_2":"test",
},
"object_name_2":{
"id":1,
"value_1":"hello",
"value_2":"test",
},
"new_object":{
"id":2,
"value_1":"hello",
"value_2":"test",
}
}
谢谢。
答案 0 :(得分:0)
这种json格式不合适。您可以更改格式并使用数组作为顺序键。但你可以使用以下方法:
JSONObject object = new JSONObject(message);
Iterator<String> keyList = object.keys();
while (keyList.hasNext()){
String key = keyList.next();
object.get(key);
//parse value and use it
}