我成功地使用 Gson 将 json 放入对象中。它在具有 android 2.2(模拟器和真实设备)的设备上就像一个魅力,当我部署到 android 4.0 及更高版本(模拟器和设备)时,我得到了这个非常奇怪的异常。
我已经确认 json 字符串没有问题,因为相同的代码在旧设备上运行良好。
这里肯定会抛出异常:
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
return gson.fromJson(jsonString, t);
在 fromJson 方法中。
有任何想法吗?
Json String:(必须从 json 中的 url 中删除 http://)
{“session_id”:“a89d8cd07e356”, “shoutout_items”:[{“attachment_url”:“xxxxxx.mobi/pic.php?id=478ba67a44d”, "attachment_url_full_size" : "xxxxxx.mobi/pic.php?id=01810a5e9f6e7065cd4", “expires_at”:1363264081, “have_attachment”:是的, "message_text" : "嗨", “合作伙伴”:{“国家代码”:“za”, “性别”:“男性”, “昵称”:“昵称”, "profile_pic_full_size_url" : "xxxxxx.mobi/pic.php?id=810a5e9f6e7065cd43629f1", "profile_pic_url" : "xxxxxx.mobi/pic.php?id=23ca67a44d23", “profile_summary”:“20,DBN” }, “shoutout_id”:31170, “类型”:“大喊” }, {“附件网址”:空, “attachment_url_full_size”:空, “expires_at”:1363264081, “有附件”:假, "message_text" : "你好", “合作伙伴”:{“国家代码”:“za”, “性别”:“男性”, “昵称”:“标记”, "profile_pic_full_size_url" : "xxxxxx.mobi/pic.php?id=2db9e7f86b9bf7ca", "profile_pic_url" : "xxxxxx.mobi/pic.php?id=b110191f1afac", “profile_summary”:“40,DBN” }, “shoutout_id”:31322, “类型”:“大喊” } ] }
堆栈跟踪:
03-14 14:56:02.200: E/AndroidRuntime(19588): FATAL EXCEPTION: main
03-14 14:56:02.200: E/AndroidRuntime(19588): java.lang.RuntimeException: Unable to start activity ComponentInfo{mobi.smiggle.android/mobi.smiggle.android.MainFragmentActivity}: java.lang.IllegalArgumentException: class android.text.BoringLayout declares multiple JSON fields named m_paint
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.app.ActivityThread.access$600(ActivityThread.java:127)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.os.Handler.dispatchMessage(Handler.java:99)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.os.Looper.loop(Looper.java:137)
03-14 14:56:02.200: E/AndroidRuntime(19588): at android.app.ActivityThread.main(ActivityThread.java:4507)
03-14 14:56:02.200: E/AndroidRuntime(19588): at java.lang.reflect.Method.invokeNative(Native Method)
03-14 14:56:02.200: E/AndroidRuntime(19588): at java.lang.reflect.Method.invoke(Method.java:511)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-14 14:56:02.200: E/AndroidRuntime(19588): at dalvik.system.NativeStart.main(Native Method)
03-14 14:56:02.200: E/AndroidRuntime(19588): Caused by: java.lang.IllegalArgumentException: class android.text.BoringLayout declares multiple JSON fields named m_paint
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:122)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.Gson.getAdapter(Gson.java:353)
03-14 14:56:02.200: E/AndroidRuntime(19588): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java: