这是我的异步任务。在 doInbackground 方法中获取 JSONException。
try {
Log.v("thisurl", url);
JSONArray data_holder = new JSONArray();
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
data_holder = json.getJSONArray(data_val);
for (int i = 0; i < data_holder.length(); i++) {
HashMap<String, String> data_map = new HashMap<String, String>();
JSONObject obj = data_holder.getJSONObject(i);
}
}
捕捉异常。但我无法从中找到原因。当我手动检查时,URL 会正确获取 json 响应。这是我的堆栈跟踪。
W/System.err(3353): org.json.JSONException: No value for searchresult
W/System.err(3353): at org.json.JSONObject.get(JSONObject.java:354)
W/System.err(3353): at org.json.JSONObject.getJSONArray(JSONObject.java:544)
W/System.err(3353): at com.store.SearchResultActivity$getJsonProductData.doInBackground(SearchResultActivity.java:318)
W/System.err(3353): at com.store.SearchResultActivity$getJsonProductData.doInBackground(SearchResultActivity.java:1)
W/System.err(3353): at android.os.AsyncTask$2.call(AsyncTask.java:287)
W/System.err(3353): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
W/System.err(3353): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
W/System.err(3353): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err(3353): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
W/System.err(3353): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
W/System.err(3353): at java.lang.Thread.run(Thread.java:856)
D/AndroidRuntime(3353): Shutting down VM
W/dalvikvm(3353): threadid=1: thread exiting with uncaught exception (group=0x40ccb300)
谁能指出我在这里做错了什么?