标签:android des style blog java color 使用 os
public synchronized <T> T parseJson(String json, Class<T> classOfT) throws Exception{ T target = null; Gson gson = new Gson(); target = gson.fromJson(json, classOfT); return target; }
之后在我的Activity中使用方式是:
String addModel = JsonParse.getJsonParse().parseJson(jsonString, AddModel.class);
//其中AddModel是自己写的一个model类
//jsonString是一个本地文件,以Json格式存在
-keep public class com.android.chebaob.model.AddModel{ *; }
而且要在proguard.cfg文件最后添加:
##---------------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.** { *; } # Application classes that will be serialized/deserialized over Gson -keep class com.google.gson.examples.android.model.** { *; } ##---------------End: proguard configuration for Gson ----------
Android混淆编译时,用到gson-2.2.2.jar进行反射解析json数据时,报ClassCastException错误,布布扣,bubuko.com
Android混淆编译时,用到gson-2.2.2.jar进行反射解析json数据时,报ClassCastException错误
标签:android des style blog java color 使用 os
原文地址:http://www.cnblogs.com/kalui/p/3875785.html