我有两个网址。
- https://wimp.supremosolutions.com/api/v1/spot/?format=json
- https://wimp.supremosolutions.com/api/v1/spot/?format=json&latitude=45.200375&longitude=9.992465000000001
如果我通过我的 android 活动运行第一个,那么结果会毫无问题地加载到我的列表中。但是,如果我运行第二个 URL,那么我就会收到此错误。
05-30 16:20:30.473: ERROR/JSON Parser(1740): Error parsing data org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
05-30 16:20:30.633: ERROR/AndroidRuntime(1740): FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at com.supremosolutions.wimp.AroundMeParking$LoadInbox.doInBackground(AroundMeParking.java:162)
at com.supremosolutions.wimp.AroundMeParking$LoadInbox.doInBackground(AroundMeParking.java:138)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
我已经通过 json 验证器(如http://jsonlint.com/ )运行了这两个 URL,并且都进行了验证。
代码似乎在jsonParser.makeHttpRequest
:
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jsonParser.makeHttpRequest(callableUrl, "GET", params);
// Check your log cat for JSON response
Log.d("JSON FOR LOGCAT: ", json.toString());
有时我可以在 Logcat 中看到 JSON FOR LOGCAT 字符串,它看起来像这样http://pastebin.com/6CWBAyys(尽管仍然会因该异常而崩溃)但有时该字符串甚至不会进入 logcat。
这里有什么问题,我该如何解决?