Gson工具包使用

   1  首先根據json串 ,構建javabeanjava

                               

public class NewsCenter {
    public List<NewsCenterItem> data;
    public List<String> extend;
    public String retcode;

    public class NewsCenterItem {
        public List<Children> children;
        public String id;
        public String type;
        public String title;
        public String url;
        public String url1;
        public String dayurl;
        public String excurl;
        public String weekurl;
    }

    public class Children {
        public String id;
        public String type;
        public String title;
        public String url;
    }
}

  2  編寫一個json工具類json

public class GsonUtil {
public static <T> T json2bean(String json,Class<T> clazz){
    Gson gson=new Gson();
    
    return gson.fromJson(json, clazz);
    
}
}

3  解析jsoncurl

 NewsCenterPager centerPager=GsonUtil.json2bean(result, NewsCenterPager.class);   
工具

相關文章
相關標籤/搜索