I'm implementing the JSONParsing but it getting the JSONException of org.json.JSONException: Value true at Status of type java.lang.String cannot be converted to JSONObject.Thanks in advanced.
Here is my Json String
{"Upd_Post_ActivityResult":{"ResponseItem":"103_20150900021028","Status":"true"}}
Here is the JSON Parsing
if (result != null) {
try
{
JSONObject jsonObj = new JSONObject(result);
String jsonResult = jsonObj.toString().trim();
Log.e("jsonResult ", " = " + jsonResult);
JSONObject json_Upd_Post_ActivityResult = jsonObj.getJSONObject("Upd_Post_ActivityResult");
Log.e("getAllActivity_List ", " = " + json_Upd_Post_ActivityResult.toString());
JSONObject jobj1 = json_Upd_Post_ActivityResult.getJSONObject("Status");
String strStatusObj = jobj1.toString();
Log.e("strStatusObj "," = " + strStatusObj);
if(strStatusObj.equals("true"))
{
Log.e("StartMark Url Uploaded ", "Succesfully !!!!!");
Log.e("Status ", "True");
int imagesArray = imgItemArray.size();
Log.e("imagesArray "," = "+imagesArray);
}
else
{
Log.e("Status ","False");
}
}
catch (JSONException je)
{
je.printStackTrace();
}
}
Here is log error
09-18 06:41:02.543 20427-20490/? W/System.err﹕ org.json.JSONException: Value true at Status of type java.lang.String cannot be converted to JSONObject
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:100)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at org.json.JSONObject.getJSONObject(JSONObject.java:613)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at com.example.tazeen.classnkk.AddPost$7$1.doInBackground(AddPost.java:320)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at com.example.tazeen.classnkk.AddPost$7$1.doInBackground(AddPost.java:286)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
09-18 06:41:02.543 20427-20490/? W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
Try the below approach:
JSONObject jobj1 = json_Upd_Post_ActivityResult.getJSONObject("Status");
String strStatusObj = jobj1.toString();
Status is not a JSONObject. So instead to getJSONObject("Status") you have to use String strStatusObj = json_Upd_Post_ActivityResult.getString("Status")
;
i have done few changes in your code , please check...
try { JSONObject jsonObj = new JSONObject(result); String jsonResult = jsonObj.toString().trim(); Log.e("jsonResult ", " = " + jsonResult);
JSONObject json_Upd_Post_ActivityResult = jsonObj.getJSONObject("Upd_Post_ActivityResult");
Log.e("getAllActivity_List ", " = " + json_Upd_Post_ActivityResult.toString());
String strStatusObj = json_Upd_Post_ActivityResult.getString("Status");
Log.e("strStatusObj "," = " + strStatusObj);
if(strStatusObj.equals("true"))
{
Log.e("StartMark Url Uploaded ", "Succesfully !!!!!");
Log.e("Status ", "True");
int imagesArray = imgItemArray.size();
Log.e("imagesArray "," = "+imagesArray);
}
else
{
Log.e("Status ","False");
}
}
catch (JSONException je)
{
je.printStackTrace();
}
}
Change this
JSONObject jobj1 = json_Upd_Post_ActivityResult.getJSONObject("Status");
to
String strStatusObj = json_Upd_Post_ActivityResult.getString("Status");
请使用下面的,让我知道它是否有效
String str=json_Upd_Post_ActivityResult.getString("Status");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.