Android的JSON对象 [英] Android JSON Object
问题描述
我有这样一个JSON格式
I have a JSON format like this
{响应:{状态:真正的结果:user_exists}}
{"response":{"status":true,"result":"user_exists"}}
现在我试图找回状态值做一些逻辑
Now i am trying to retrieve the Status value to do some logic
JSONObject jData = new JSONObject(data);
JSONArray response = jData.getJSONArray("response");
但我收到以下错误
But i am getting the following error
org.json.JSONException:值{结果:user_exists,状态:真} 在类型org.json.JSONObject的响应不能转换到 JSONArray
org.json.JSONException: Value {"result":"user_exists","status":true} at response of type org.json.JSONObject cannot be converted to JSONArray
如何从内检索对象和对象?
how to retrieve an Object from inside and Object ?
推荐答案
您正在尝试中检索从 JSONArray
但是,你没有任何地位attribut JSONArray
在code,( JSONArray
是 []
和的JSONObject
是 {}
),
所以中检索状态值,试试这个:
you are trying to retreive the status attribut from a JSONArray
but , you don't have any JSONArray
in your Code , ( JSONArray
is surrounded by []
, and JSONObject
is surrounded by {}
) ,
So to retreive the status value , try this :
JSONObject jData = new JSONObject(data);
JSONObject response = jData.getJSONObject("response");
boolean status = response.getBoolean("status");
这篇关于Android的JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!