Java 在android应用程序中获取json值
在android应用程序中获取json值Java 在android应用程序中获取json值,java,android,json,Java,Android,Json,在android应用程序中获取json值 my json result = {"message":"Json","success":1} Value {"message":"Json","success":1} of type org.json.JSONObject cannot be converted to JSONArray my code : HttpEntity ent= resp.getEntity(); te
my json result = {"message":"Json","success":1}
Value {"message":"Json","success":1} of type org.json.JSONObject cannot be converted to JSONArray
my code :
HttpEntity ent= resp.getEntity();
text = EntityUtils.toString(ent);
JSONArray json = new JSONArray(text);
JSONObject jObj = json.getJSONObject(0);
Integer sucess= jObj.getInt("success");
if (sucess == 1){
Log.v("JSON" ,"es 1");
}
您正在尝试将JSONObject转换为JSONArray 用这个
HttpEntity ent= resp.getEntity();
text = EntityUtils.toString(ent);
JSONObject json = new JSONObject(text);
int success= -1;
if(json.has("success"))
success = json.getInt("success");
if (success == 1){
Log.v("JSON" ,"es 1");
}