0
String wat = "";

        try{
                JSONObject responsee = new JSONObject(result);
                wat = responsee.getString("Result");
            }
            catch(JSONException e){
                    Log.e("log_tag", "Error parsing data "+e.toString());
            }

結果={"結果":"D"}

このコードはアプリケーションをクラッシュさせ、次のエラーをスローします。

Error parsing data org.json.JSONException: No value for {"Result":"D"}

4

2 に答える 2

3

responseeそれ自体が必要なjsonオブジェクトです。あなたはそれを呼び出す必要はありませんgetJSONObject。を使用するだけresponsee.getString("Result");です。以下を使用する必要がある場合の例を次に示しますgetJsonObject

// result = {"name": "John", "age": 10, "father": {"name": "Tom", "age": 30"}}

JSONObject response = new JSONObject(result);
JSONObject father = response.getJSONObject("father");
String fathersName = father.getString("name");
于 2013-02-11T14:12:48.753 に答える
3

これを試して:

JSon Response like  below
 {"data": { "name": "AAA", "Age": "11"}}

そのコードを使用して、以下のデータを取得します。

  JSONObject response = new JSONObject(result);
  JSONObject json= response.getJSONObject("data");
  String Name = json.getString("name");
  String Age =json.getString("Age");

応答は次のとおりです。AAAおよび11

于 2013-02-11T14:24:36.140 に答える