{
"hits": [
{
"name": "Google",
"results": [
{
"count": 27495
}
]
},
{
"name": "Yahoo",
"results": [
{
"count": 17707
}
]
}
}
我能夠通過下面的代碼讀取上述json的名稱和結果,但無法從JSON單獨打印計數值。如何提取JSON數組中的JSON數組
JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
if(null!=jsonObject.get("hits"))
{
System.out.println("Inside IF...");
JSONArray ja = (JSONArray) jsonObject.get("hits");
for(int i=0;i<ja.size() ; i++)
{
System.out.println("Inside FOR...");
JSONObject tempJsonObj = (JSONObject) ja.get(i);
System.out.println(tempJsonObj.get("name").toString());
System.out.println(tempJsonObj.get("results").toString());
}
}
如何提取JSON陣列
[解析JSON陣列(http://stackoverflow.com/questions/854028/parse-json-array) – Mohit
HTTP的可能的複製://計算器.com/a/31019989/3126639 – Waqar