简体   繁体   English

JSONObject不适用于Android 2.3但适用于Android 4.2,为什么?

[英]JSONObject not working for Android 2.3 but works fine with Android 4.2, why?

I am requesting server for a JSONObject and it contains a list of some ids. 我正在请求服务器的JSONObject,它包含一些ID的列表。 This is working fine with Android 4.2 but not working with Android 2.3 (have tested on both Device and Emulator.) 这适用于Android 4.2,但不适用于Android 2.3(已在设备和模拟器上进行过测试。)

The JSONObject is as follows. JSONObject如下。

{"IdList":[{"id":"004502"},{"id":"S007901"},{"id":"041501"},{"id":"S139001"}]}

This works fine with 4.2, but shows NullPointerException in 2.3. 这适用于4.2,但在2.3中显示NullPointerException

My LogCat is as follows: 我的LogCat如下:

org.json.JSONException: Value Nullpointer of type java.lang.String cannot be converted to JSONObject
06-06 11:23:46.881: W/System.err(1820):     at org.json.JSON.typeMismatch(JSON.java:107)
06-06 11:23:46.893: W/System.err(1820):     at org.json.JSONObject.<init>(JSONObject.java:158)
06-06 11:23:46.893: W/System.err(1820):     at org.json.JSONObject.<init>(JSONObject.java:171)
06-06 11:23:46.893: W/System.err(1820):     at my.Site.serverInterface.executeHttpRequest(serverInterface.java:128)
06-06 11:23:46.893: W/System.err(1820):     at my.Site.serverInterface.getAtmId(serverInterface.java:54)
06-06 11:23:46.901: W/System.err(1820):     at my.Site.TrackLocation$AtmGetter.doInBackground(TrackLocation.java:379)
06-06 11:23:46.901: W/System.err(1820):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-06 11:23:46.901: W/System.err(1820):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-06 11:23:46.901: W/System.err(1820):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-06 11:23:46.901: W/System.err(1820):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-06 11:23:46.901: W/System.err(1820):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-06 11:23:46.901: W/System.err(1820):     at java.lang.Thread.run(Thread.java:1019)
06-06 11:23:46.901: I/System.out(1820): null
06-06 11:23:46.912: I/System.out(1820)://e
06-06 11:23:46.912: W/System.err(1820): java.lang.NullPointerException
06-06 11:23:46.912: W/System.err(1820):     at my.Site.TrackLocation$AtmGetter.doInBackground(TrackLocation.java:384)
06-06 11:23:46.912: W/System.err(1820):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-06 11:23:46.912: W/System.err(1820):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-06 11:23:46.912: W/System.err(1820):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-06 11:23:46.912: W/System.err(1820):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-06 11:23:46.912: W/System.err(1820):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-06 11:23:46.912: W/System.err(1820):     at java.lang.Thread.run(Thread.java:1019)
06-06 11:23:46.921: W/dalvikvm(1820): threadid=10: thread exiting with uncaught exception (group=0xb60c84f0)
06-06 11:23:46.931: E/AndroidRuntime(1820): FATAL EXCEPTION: AsyncTask #3
06-06 11:23:46.931: E/AndroidRuntime(1820): java.lang.RuntimeException: An error occured while executing doInBackground()
06-06 11:23:46.931: E/AndroidRuntime(1820):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.lang.Thread.run(Thread.java:1019)
06-06 11:23:46.931: E/AndroidRuntime(1820): Caused by: java.lang.NullPointerException
06-06 11:23:46.931: E/AndroidRuntime(1820):     at my.Site.TrackLocation$AtmGetter.doInBackground(TrackLocation.java:427)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-06 11:23:46.931: E/AndroidRuntime(1820):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-06 11:23:46.931: E/AndroidRuntime(1820):     ... 4 more

download the org.json jar and import it. 下载org.json jar并导入它。 It should work for 2.3 also. 它也适用于2.3。

Refer this .. 请参考..

JSON Parsing works on Android 4.0 but not on Android < 4.0 JSON解析适用于Android 4.0,但不适用于Android <4.0

Have you tried setting the responseType to json . 您是否尝试将responseType设置为json If the issue still exists there are some suggestions in these posts 如果问题仍然存在,这些帖子中有一些建议

JSON Parsing works on Android 4.0 but not on Android < 4.0 JSON解析适用于Android 4.0,但不适用于Android <4.0

Issue initializing a JSONObject 初始化JSONObject的问题

JSON parsing problem JSON解析问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 代码在Android 4.2上不起作用,但在Android 2.3上可以 - code not working on Android 4.2 but ok on Android 2.3 JSON无法在android 4.2上运行,但在android 2.2上可以正常运行,为什么? - JSON not working on android 4.2 but work fine on android 2.2, why? 基于套接字连接的应用程序在Android 2.3中效果很好,但在Android 4.2中效果不佳 - Application based on socket connection, works well in Android 2.3 but not in android 4.2 查看-&gt; getParent()在Android 2.3中工作正常,但在Android 4+中抛出NullPointerException - View -> getParent() works fine in Android 2.3 but throwing NullPointerException in Android 4+ 在Android 4.2上获取异常,但在Android 5.0上可以正常工作 - Getting exception on android 4.2 but works fine on android 5.0 Android onContentChanged on 2.3 vs 4.2 - Android onContentChanged on 2.3 vs 4.2 在Android 2.2上具有Cookie的NullPointer异常-在2.3及更高版本上可以正常工作 - NullPointer Exception with Cookie on Android 2.2 - works fine on 2.3 and above GZIPInputStream在Android 2.3中因IOException失败,但在以前的所有版本中都能正常工作吗? - GZIPInputStream fails with IOException in Android 2.3, but works fine in all previous releases? 在android 2.3设备上没有对等证书错误,但在android 4+上可以正常工作 - No peer certificate error on android 2.3 devices but working fine on android 4+ 为什么当setData()和setType()不起作用时,android intent的setDataAndType()工作正常? - why setDataAndType() for an android intent works fine when setData() and setType() are not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM