2015-01-13 125 views
1

我的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 
+0

如在日誌'registerResponse'無效JSON字符串 –

+0

按您的logcat節目「<體的onload =‘ABC()’>」隨附響應,這不是有效的格式.. – duggu

+0

可能重複[如何在Android中解析JSON](http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android) – DroidDev

回答

0

的registerResponse不具有上面指定爲JSON值。您可以在日誌中看到'腳本'標籤。

我想你是錯誤地加載一個html或一些網址,它返回html內容來獲取JSON。您的服務器應該以純文本的形式返回JSON而不使用html標記。

+0

謝謝!問題解決了.. – nav123

0

剛剛檢查了你的源代碼發現了一些腳本和html。我們嚴格需要「application/json」mimetype作爲服務器的響應。

1

是得到你的問題你沒有得到JSON響應作爲響應你有所有的服務響應看到日誌貓的第一行。

這就是爲什麼你無法將其轉換爲JSONObject。編輯你的服務,並從中返回JSONObject。