Hesson decided that all of Json's riots was extremely light.
Anyway, I used Gson in java on Android and looked like this:
static public <T extends JsonAble> T getJson(Context context, Class<T> jsonClass){
String strClassName = jsonClass.getSimpleName();
String strJson = getTextFromFile(context, strClassName);
T objReturn = gsnEncoder.fromJson(strJson, jsonClass);
return objReturn;
}
As you can see, you just need to select the object, and Gson will do the magic.
EDIT: I sent fromJson instead of toJson), the idea is the same, give me a second to fix this.
static public <T extends JsonAble> boolean setObject(Context context, T Obj) {
boolean IsSucceed = false;
String strClassName = Obj.getClass().getSimpleName();
try {
String strObj = DL.gsnEncoder.toJson(Obj);
IsSucceed = DL.setTextToFile(context, strClassName, strObj);
} catch (Exception e) {
e.printStackTrace();
}
return IsSucceed;
}
source
share