嘿家伙所以我试图解析这个json来获取所有sName
我一直未能得到它们我只能设法只获得1个名字并不是所有的json
不知道接下来该做什么我想为它做一个声明吗?
有什么想法吗?或代码示例谢谢!
请注意我正在使用JAVA json libary!
我的代码:
String text = MainUI.json_text.getText();
try {
JSONObject json = new JSONObject(text);
Iterator<String> iter = json.keys();
while (iter.hasNext()) {
try {
Object value = json.getString("sName");
System.out.println(value);
} catch (JSONException e) {
System.out.println("Failed:" + e.toString());
}
}
} catch (JSONException ex) {
Logger.getLogger(Quest_Json.class.getName()).log(Level.SEVERE, null, ex);
}
JSON:
{
"sFaction":"None",
"iClass":0,
"oRewards":{
"itemsS":{
"0":{
"ItemID":"17109",
"sLink":"",
"sElmt":"None",
"bStaff":0,
"iRng":10,
"bCoins":0,
"iDPS":0,
"sES":"None",
"sType":"Item",
"iCost":0,
"iRty":10,
"iQSValue":0,
"iQty":10,
"sReqQuests":"",
"sIcon":"iibag",
"iLvl":1,
"bTemp":0,
"bPTR":0,
"iQSIndex":-1,
"iStk":40,
"sDesc":"Use this to merge into epic gear in the shop!",
"bHouse":0,
"bUpg":0,
"bQuest":0,
"sName":"Realm Gem"
}
}
},
"sField":"id2",
"bOnce":1,
"bStaff":0,
"iValue":4,
"iGold":1000,
"oItems":{
"17107":{
"sIcon":"iibag",
"ItemID":17107,
"iLvl":1,
"sLink":"",
"sElmt":"None",
"bTemp":1,
"bStaff":0,
"iRng":1,
"bCoins":0,
"iDPS":0,
"sES":"None",
"bPTR":0,
"iQSIndex":-1,
"sType":"Quest Item",
"sDesc":"Well done, Hero!",
"iStk":5,
"iCost":0,
"bUpg":0,
"bHouse":0,
"iRty":10,
"sName":"Wolf Defeated",
"iQSValue":0,
"sReqQuests":2819
}
}
}
结果:
你的第五个任务:水生物
你的第五个任务:水生物
你的第五个任务:水生物
你的第五个任务:水生物
你的第五个任务:水生物
等等!
但是它应该总是让每个sName都不一样!