Json类型不匹配

时间:2015-01-13 05:55:59

标签: java android json

我的json数据

 {"status":"true","c_id":"72","u_name":"navneet","dob":"2015-01-12","description":"login sucessful"}

解析json数据的代码

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;
}

错误是:

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

3 个答案:

答案 0 :(得分:1)

是您的问题您没有得到JSON响应作为响应,您正在响应所有服务,请参阅log cat的第一行。

这就是为什么你无法将它转换为JSONObject。编辑您的服务,然后从中返回JSONObject。

答案 1 :(得分:0)

registerResponse没有您在上面指定为JSON的值。你可以看到&#39;脚本&#39;日志中的标记。

我猜你错误地加载了一个html或一些返回html内容以获取JSON的网址。您的服务器应该将JSON作为纯文本返回,而不使用html标记。

答案 2 :(得分:0)

刚查过你的源代码,发现了一些脚本和html。我们严格需要&#34; application / json&#34; mimetype作为服务器的响应。