我正在尝试使用LoganSqure
解析器序列化json
我在我的java构建路径中添加了以下jar
jackson-annotations-2.5.0.jar
jackson-core-2.5.0.jar
logansquare-1.0.3.jar
logansquare-compiler-1.0.5.jar
以下是我的模特
@JsonObject
public class Image {
/*
* Standard field declaration.
*/
@JsonField
public String format;
}
但我仍然遇到以下错误
07-16 10:30:09.360: E/AndroidRuntime(9313): Process: com.princepipe.fsa, PID: 9313
07-16 10:30:09.360: E/AndroidRuntime(9313): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.fsa/com.fsa.MainActivity}: com.bluelinelabs.logansquare.NoSuchMapperException: Class com.princepipe.model.Image could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.os.Handler.dispatchMessage(Handler.java:102)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.os.Looper.loop(Looper.java:136)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.reflect.Method.invoke(Method.java:515)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-16 10:30:09.360: E/AndroidRuntime(9313): at dalvik.system.NativeStart.main(Native Method)
07-16 10:30:09.360: E/AndroidRuntime(9313): Caused by: com.bluelinelabs.logansquare.NoSuchMapperException: Class com.princepipe.model.Image could not be mapped to a JSON object. Perhaps it hasn't been annotated with @JsonObject?
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.bluelinelabs.logansquare.LoganSquare.mapperFor(LoganSquare.java:130)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.bluelinelabs.logansquare.LoganSquare.serialize(LoganSquare.java:80)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.princepipe.fsa.MainActivity.serialzieRequest(MainActivity.java:89)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.princepipe.fsa.MainActivity.onCreate(MainActivity.java:43)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.Activity.performCreate(Activity.java:5231)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-16 10:30:09.360: E/AndroidRuntime(9313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-16 10:30:09.360: E/AndroidRuntime(9313): ... 11 more
07-16 10:30:09.360: E/AndroidRuntime(9313): Caused by: java.lang.ClassNotFoundException: com.fsa.model.Image$$JsonObjectMapper
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.Class.classForName(Native Method)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.Class.forName(Class.java:251)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.Class.forName(Class.java:216)
07-16 10:30:09.360: E/AndroidRuntime(9313): at com.bluelinelabs.logansquare.LoganSquare.mapperFor(LoganSquare.java:126)
07-16 10:30:09.360: E/AndroidRuntime(9313): ... 17 more
07-16 10:30:09.360: E/AndroidRuntime(9313): Caused by: java.lang.NoClassDefFoundError: com/fsa/model/Image$$JsonObjectMapper
07-16 10:30:09.360: E/AndroidRuntime(9313): ... 21 more
07-16 10:30:09.360: E/AndroidRuntime(9313): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.princepipe.model.Image$$JsonObjectMapper" on path: DexPathList[[zip file "/data/app/com.fsa-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.fsa-1, /system/lib]]
07-16 10:30:09.360: E/AndroidRuntime(9313): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-16 10:30:09.360: E/AndroidRuntime(9313): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-16 10:30:09.360: E/AndroidRuntime(9313): ... 21 more
以下是我如何序列化
Image i = new Image();
try {
String data = LoganSquare.serialize(i);
Log.e("Data ", data+"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSON请求非常简单我只是想创建一个示例请求
{"format":"png"}