-1

私は D3 DPS 計算機に取り組んでおり、JSON オブジェクトに問題があります。次のような 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}}

この値をすべて分割するにはどうすればよいですか? 「ランダム」なので、名前で行うことはできません。統計と値のリストが必要です。

4

4 に答える 4

0

統計の名前がわからない場合は、 で取得できますJSONObject.names()

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");
}
于 2013-05-12T16:57:04.567 に答える
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");

これが役立つことを願っています。

于 2013-05-12T16:05:12.897 に答える
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"
            }
        ]
    }
}

ジャバコード

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");
         }

それで全部です

于 2013-05-12T16:10:28.277 に答える
0

役立つかもしれないことの 1 つは、このようなオンラインJSON ビューアで JSON を表示することです。format を押すと、次のようなものが得られます。

{
  "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 解析に関するこの説明がとても気に入っています。

于 2013-05-12T15:59:12.467 に答える