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 回答