我json
響應:獲取價值觀和名稱的名稱
{
"Countries": [
{
"Country": "China",
"Alpha2": "CN",
"Alpha3": "CHN",
"numbers": {
"Jon": "100",
"Mat": "200",
"SAM": "300"
}
},
{
"Country": "Italy",
"Alpha2": "IT",
"Alpha3": "ITA",
"numbers": {
"Benny": "400",
"Jack": "500"
}
}
]
}
我的代碼:
for (int i = 0; i < m_jArry.length(); i++) {
JSONObject jo_inside = m_jArry.getJSONObject(i);
if (jo_inside.getString("Country").equals("Italy"))
{
Log.d("DTAG",jo_inside.getString("Country"));
Log.d("DTAG",jo_inside.getString("Alpha2"));
Log.d("DTAG", jo_inside.getString("Alpha3"));
JSONObject jo_inside2 = jo_inside.getJSONObject("numbers");
Log.d("DTAG", "Size: "+jo_inside2.length());
for (int j=0;j<jo_inside2.length();j++)
{
//???
}
}
我怎樣才能獲得的價值和他的價值的名字嗎? 對於這個例子我需要得到本尼400,傑克500
我認爲這是你要搜索的內容:http://stackoverflow.com/questions/13573913/android- jsonobject-how-can-i-loop-through-a-flat-json-object-to-get-each-key-a – Blunderer
這是比較複雜的文章,但它確實回答你的問題http://stackoverflow.com/questions/12870332/how-can-i-iterate-jsonobject-to-get-individual-items – Rohit5k2