Android中使用gson进行json数据解析的注意事项
分类:Android, Java
阅读 (2,205)
Add comments
10月 272016
转载请注明原文地址:http://bcoder.com/java/attentions-when-using-gson-to-parse-json-data-in-android-development
使用gson进行数据解析后,必须在混淆脚本中添加如下代码,如果不加的话json解析就会失败。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
##---------------Begin: proguard configuration for Gson ---------- # Gson uses generic type information stored in a class file when working with fields. Proguard # removes such information by default, so configure it to keep all of it. -keepattributes Signature # For using GSON @Expose annotation -keepattributes *Annotation* # Gson specific classes -keep class sun.misc.Unsafe { *; } #-keep class com.google.gson.stream.** { *; } -keepclassmembers class * { public <init> (org.json.JSONObject); } # Application classes that will be serialized/deserialized over Gson -keep class com.bcoder.test.datatypes.** { *; } ##---------------End: proguard configuration for Gson ---------- |
其中-keep class com.bcoder.test.datatypes.** { *; }这一行class和.**之间改成你的Bean类所在的包名