我有这个 JSON 文件,它被读取并存储在一个String
被调用的文件中jsonString
,它看起来像这样:
{
"position":1,
"team_id":10260,
"home":
{
"played":18,
},
},
{
"position":2,
"team_id":8456,
"home":
{
"played":12,
},
},
解析代码:
JSONObject obj = new JSONObject(jsonString);
Iterator it = obj.keys();
while(it.hasNext()){
String s = it.next().toString();
System.out.print(s + " " + obj.getString(s) + " ");
}
输出是:position 1 home {"played":18} team_id 10260
所以它不会读取文件的其余部分。你能告诉我有什么问题吗?还有,为什么home {"played":18}
之前打印team_id 10260
?