String wat = "";
try{
JSONObject responsee = new JSONObject(result);
wat = responsee.getString("Result");
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
result = {“结果”:“D”}
此代码崩溃应用程序并抛出以下错误:
Error parsing data org.json.JSONException: No value for {"Result":"D"}
答案 0 :(得分:2)
试试这个:
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
答案 1 :(得分:1)
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");