A JSON tool class that provides a conversion between JSON and objects.
The source code is as follows: (Click to download-Jsonutils.java, Gson-2.2.4.jar)
ImportJava.lang.reflect.Type;ImportJava.util.Map;ImportCom.google.gson.Gson;ImportCom.google.gson.GsonBuilder;/*** JSON Tool class **/@SuppressWarnings ("Unchecked") Public classJsonutils {Private StaticGson Gson; Privatejsonutils () {}Static{gsonbuilder GB=NewGsonbuilder (); Gb.setdateformat ("Yyyy-mm-dd HH:mm:ss"); Gson=gb.create (); } Public Static FinalString ToJson (Object obj) {returnGson.tojson (obj); } Public Static Final<T> T Fromjson (FinalString JSON, class<t>clazz) { returnGson.fromjson (JSON, clazz); } Public Static Final<T> T Fromjson (FinalString json, Type t) { returnGson.fromjson (JSON, T); } Public Static FinalMap<string, Object> Fromjson (FinalString JSON) { returnFromjson (JSON, Map.class); }}
JSON Tool Class-Jsonutils.java