請指教我爲什麼log cat告訴我org.json.JSONException:沒有report_data的值。 而我的PHP文件是工作。請幫助我瞭解有關Android連接到MySQL的信息。 logcat告訴我這個org.json.JSONException:沒有report_data的值
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_REPORT_ID, report_id));
JSONObject json = jsonParser.makeHttpRequest(ReportURL, "GET", params);
Log.d("details", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray detailsObj = new JSONArray();
detailsObj = json.getJSONArray(TAG_REPORT_DATA); // error this line
JSONObject details = detailsObj.getJSONObject(0);
}
這裏所有的日誌貓展
09-17 11:55:59.723: D/details(4097): {"success":1,"detail":[{"uid":"1","time_end":"2012-08-21 15:50:37","time_start":"2012-08-15 15:40:31","report_id":"1","project_name":"example1","location":"bkk"}]}
09-17 11:55:59.723: W/System.err(4097): org.json.JSONException: No value for report_data
09-17 11:55:59.723: W/System.err(4097): at org.json.JSONObject.get(JSONObject.java:354)
09-17 11:55:59.723: W/System.err(4097): at org.json.JSONObject.getJSONArray(JSONObject.java:544)
09-17 11:55:59.723: W/System.err(4097): at com.example.androidhive.ReportEdit$GetReportDetails$1.run(ReportEdit.java:131)
09-17 11:55:59.734: W/System.err(4097): at android.os.Handler.handleCallback(Handler.java:615)
09-17 11:55:59.734: W/System.err(4097): at android.os.Handler.dispatchMessage(Handler.java:92)
09-17 11:55:59.734: W/System.err(4097): at android.os.Looper.loop(Looper.java:137)
09-17 11:55:59.734: W/System.err(4097): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-17 11:55:59.743: W/System.err(4097): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 11:55:59.743: W/System.err(4097): at java.lang.reflect.Method.invoke(Method.java:511)
09-17 11:55:59.743: W/System.err(4097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-17 11:55:59.743: W/System.err(4097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-17 11:55:59.754: W/System.err(4097): at dalvik.system.NativeStart.main(Native Method)
檢查出你的JSON解析器代碼 –
元素你可以在這裏發佈你的日誌,因爲它可以幫助我們找到問題到底在哪裏。 – ponraj
檢查此Log.d(「details」,json.toString());你在收到併發布在這裏 – Akram