Reputation: 11
my json data
{"status":"true","c_id":"72","u_name":"navneet","dob":"2015-01-12","description":"login sucessful"}
code for parsing json data
try {
Log.d("oooooooooooo",registerResponse);
JSONObject responseObject = new JSONObject(registerResponse);
Log.d("", "responseObjectresponseObject" + responseObject);
Status = responseObject.getString("status");
Log.d("", "StatusStatusStatus" + Status);
res_Desp = responseObject.getString("description");
Log.d("", "Status_DespStatus_DespStatus_Desp" + res_Desp);
} catch (Throwable t) {
Log.e("zxxxxxxxxxx",
"Error parsing response of change password web service - "
+ t.getMessage());
t.printStackTrace();
// return Boolean.FALSE;
}
errors are:
01-13 11:07:02.049 11363-11490/com.example.welcome.kids_chat D/oooooooooooo﹕ <script> function abc(){if(window.location.href=="http://corouter.com/res/kidschat/login.php"){ window.location.assign('http://corouter.com/res/kidschat/login.php?username=&password='); }}</script><body onload="abc()"></body> {"status":"true","c_id":"72","u_name":"navneet","dob":"2015-01-12","description":"login sucessful"}
01-13 11:07:02.049 11363-11490/com.example.welcome.kids_chat E/zxxxxxxxxxx﹕ Error parsing response of change password web service - Value http of type java.lang.String cannot be converted to JSONObject
01-13 11:07:02.049 11363-11490/com.example.welcome.kids_chat W/System.err﹕ org.json.JSONException: Value http of type java.lang.String cannot be converted to JSONObject
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:111)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:159)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:172)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at com.example.welcome.kids_chat.Login_Screen$loadslashscreenTask1.doInBackground(Login_Screen.java:162)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at com.example.welcome.kids_chat.Login_Screen$loadslashscreenTask1.doInBackground(Login_Screen.java:80)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-13 11:07:02.059 11363-11490/com.example.welcome.kids_chat W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
01-13 11:07:02.079 11363-11363/com.example.welcome.kids_chat D/AndroidRuntime﹕ Shutting down VM
Upvotes: 1
Views: 845
Reputation: 2917
The registerResponse is not having the value you specified above as JSON. You can see 'script' tag in the logs.
I guess you are by mistake loading an html or some web url which returns html content to get JSON. Your server should return the JSON as plain text without html tags.
Upvotes: 0
Reputation: 9121
Yes Got your Problem You are not getting JSON response as response you are having all service in response see the first line of log cat.
Thats why you are unable to convert it to JSONObject. Edit your service and just return JSONObject from that.
Upvotes: 1
Reputation: 11
Just checked your source code found some script and html. We strictly need "application/json" mimetype as a response from server.
Upvotes: 0