1

请告诉我为什么 log cat 告诉我 org.json.JSONException:report_data 没有值。我的 php 文件可以正常工作。

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)
4

2 回答 2

0

问题在于您的 JSON 解析。试试这个代码

detailsObj = json.getJSONArray("detail");

代替

detailsObj = json.getJSONArray(TAG_REPORT_DATA);
于 2012-09-17T06:47:55.433 回答
0

问题似乎是您在 JSON 中没有名为“report_data”的元素

于 2012-09-17T07:42:59.750 回答