简体   繁体   中英

Convert to JSON from JAVA

This has been cleared and worked. I'm sorry I can't save the code here because it might be taken and could be taken as copyrighted which I do not allowed! If needed help, please email me and I will help!

According to my knowledge no need to do extra efforts for implementing the interface and override the method. You can create JSON string from the object using below code snippet.

new Gson().toJson(model);

and if you are converting JSON string into collection object then

List<Model> models= new ArrayList<Model>();
Type t = new TypeToken<List<Model>>() {
                }.getType();
models= (List<Model>) new Gson().fromJson(jsonString, t);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM