我正在研究D3 DPS计算器,我遇到了JSON-Object的问题。 我得到一个像这样的JSON-Object:
{"Sockets":{"min":1,"max":1},
"Dexterity_Item":{"min":165,"max":165},
"Durability_Cur":{"min":581,"max":581},
"Durability_Max":{"min":715,"max":715},
"Attacks_Per_Second_Item_Percent":{"min":0.1,"max":0.1},
"Damage_Weapon_Delta#Arcane":{"min":315,"max":315},
"Damage_Weapon_Min#Arcane":{"min":274,"max":274},
"Damage_Weapon_Delta#Physical":{"min":161,"max":161},
"Damage_Weapon_Min#Physical":{"min":190,"max":190},
"Attacks_Per_Second_Item":{"min":1.2000000476837158,"max":1.2000000476837158},
"Steal_Health_Percent":{"min":0.03,"max":0.03}}
我如何拆分所有这些值?我不能通过名字来做,因为它是“随机的”。我希望有一个包含统计数据和值的列表。
答案 0 :(得分:0)
可能有用的一件事是在在线JSON viewer like this中查看您的JSON。您可以点击格式,并从中获取如下内容:
{
"Sockets": {
"min": 1,
"max": 1
},
"Dexterity_Item": {
"min": 165,
"max": 165
},
"Durability_Cur": {
"min": 581,
"max": 581
},
"Durability_Max": {
"min": 715,
"max": 715
},
"Attacks_Per_Second_Item_Percent": {
"min": 0.1,
"max": 0.1
},
"Damage_Weapon_Delta#Arcane": {
"min": 315,
"max": 315
},
"Damage_Weapon_Min#Arcane": {
"min": 274,
"max": 274
},
"Damage_Weapon_Delta#Physical": {
"min": 161,
"max": 161
},
"Damage_Weapon_Min#Physical": {
"min": 190,
"max": 190
},
"Attacks_Per_Second_Item": {
"min": 1.2000000476837158,
"max": 1.2000000476837158
},
"Steal_Health_Percent": {
"min": 0.03,
"max": 0.03
}
}
另外,我非常喜欢用于Android JSON解析的this description
答案 1 :(得分:0)
如果你在Android平台上开发,你可以轻松使用 json api : http://developer.android.com/reference/org/json/JSONObject.html
你只需要实现一个JSONObject:
JSONObject jsonObject = new JSONObject(myStringData)
并使用json String (min, max,...)
int min = jsonObject.getInt("min");
我希望这会有所帮助。
答案 2 :(得分:0)
仅使用JSON api
的示例JSON文件:
{
"chapitres":{
"chapitre":[
{
"id": "1",
"name": "La plateforme Android 1",
"desc": "Description chapitre 1"
},
{
"id": "2",
"name": "La plateforme Android 2",
"desc": "Description chapitre 2"
},
{
"id": "3",
"name": "La plateforme Android 3",
"desc": "Description chapitre 3"
},
{
"id": "4",
"name": "La plateforme Android 4",
"desc": "Description chapitre 4"
}
]
}
}
JAVA代码:
JSONObject jsonObject = new JSONObject(json);
JSONObject chapitresJsonObject = jsonObject.getJSONObject("chapitres");
JSONArray chapitreJsonArray = chapitresJsonObject.getJSONArray("chapitre");
for (int i = 0; i < chapitreJsonArray.length(); i++) {
JSONObject ChapJsonObject = chapitreJsonArray.getJSONObject(i);
String id = ChapJsonObject.getString("id");
String name = ChapJsonObject.getString("name");
String desc = ChapJsonObject.getString("desc");
}
这就是全部
答案 3 :(得分:0)
如果您不知道统计信息的名称,可以使用JSONObject.names()
获取。{/ p>
JSONObject json = new JSONObject(...);
JSONArray stats = json.names();
for (int i = 0; i < stats.length(); i++) {
String name = stats.getString(i);
JSONObject stat = json.getJSONObject(name);
stat.getInt("min");
stat.getInt("max");
}