For the following JSON data:
Encapsulate using the following bean:
public class Newbean {public Newbeanitem data;public string Retcode;public class Newbeanitem{public string Countcommentur l;//Loading public string More;public string title;public list<news> news;public list<topic> topic;public List& Lt Topnews> topnews;} /** * Bottom ListView Display Entry JavaBean * @author Administrator * */public class News{public string Comment;public string Commentlis T;public string commenturl;//Uniqueness Flag Current News entry public string id;//News list Picture public string listimage;//time publicly string pubdate;// The title text of the News list public string Title;public string Type;public string url;//whether the news has read the flag bit public boolean isread;} public class Topic{public String Description;public string Id;public string listimage;public string sort;public string tit Le;public String URL;} /** * Top Carousel Map * @author Administrator * */public class Topnews{public string Comment;public string Commentlist;public string Commenturl;public string id;//Carousel map Picture link Address public string topimage;//time publicly string pubdate;//News list title text publicly string title ;p ublic string type;public string URL;}}
That is: Data is a bean, and [] represents a list collection
NOTE: null for JSON data returned by the server, the general processing is that if the field is null, the server is asked to return "" instead of NULL
Use Gson to parse the code as follows:
public class Gsonutil {/** * converts JSON string to JavaBean object * @param result * @param clazz * @return */public static <T> T JS Ontobean (String result,class<t> clazz) {Gson Gson = new Gson (); return Gson.fromjson (Result,clazz);}}
The tool class is called directly:
Newcenter = Gsonutil.jsontobean (result, newcenter.class);
JSON data encapsulation and the use of Gson to encapsulate JSON data into beans