我想将不同的List集合传递给GSON中的TypeToken类.这是我的课
public class ConvertToObject {
public T MappFrom(InputStream is)
String json = ConvertJsonInputStream.toString(is);
Gson gson = new Gson();
Type typeOfDest = new TypeToken() {
}.getRawType();
T lstObject = gson.fromJson(json, typeOfDest);
return lstObject ;
}
}
现在我想以不同的方式实例化我的类如下:
AssetManager am = getApplicationContext().getAssets();
InputStream is = am.open("form.txt");
ConvertToObject> co = new ConvertToObject>();
List
JsonForm = co.MappFrom(is);InputStream is2 = am.open("Messages.txt");
ConvertToObject> co = new ConvertToObject>();
List JsonForm = co.MappFrom(is2);
我的资产文件夹中有27个Json txt文件,我想将这些JSON txt文件解析为适当的类.我该怎么做?
Editted:
这样我就抓住了一个异常:
Caused by: java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to com.mypackage.Form