Back to project page doubanbook4android.
The source code is released under:
Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...
If you think the Android project doubanbook4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.study.doubanbook_for_android.utils; /*from w w w .j av a 2 s.c o m*/ import java.util.ArrayList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; public class JsonParser { /** * ?????????????????? * * @param json * @param token * ?? new TypeToken<ArrayList<TYPE>>(){}; * @return ArrayList<TYPE> */ public static <T> ArrayList<T> getFromJson(String json, TypeToken<?> token) { Gson gson = new Gson(); // ArrayList<T> all = gson.fromJson(json, token.getType()); return gson.fromJson(json, token.getType()); } public static <T> T getFromJsonstr(String json, TypeToken<?> token) { Gson gson = new Gson(); // ArrayList<T> all = gson.fromJson(json, token.getType()); return gson.fromJson(json, token.getType()); } /** * ??ArrayList<TYPE>?????JSON???????? * * @param all * = ArrayList<TYPE> * @return */ public <T> String parseToJsons(ArrayList<T> all) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String result = gson.toJson(all); return result; } }