public List<HashMap<String, NewsCategoryEntity>>getNesCategory(int starttid,int count)throws Exception
{
String result="{"ret":0,"msg":"ok","data":{"totalnum":3,"info":[{"title":"时尚","cid":17},{"title":"正能量","cid":16},{"title":"健康","cid":15}]}}";
JSONObject jsonObject = new JSONObject(result);
List<HashMap<String, NewsCategoryEntity>> newsCategorys=null;
int ret=jsonObject.getInt("ret");
if(0==ret)
{
JSONObject dataObject=jsonObject.getJSONObject("data");
int totalNum=dataObject.getInt("totalnum");
if(totalNum>0)
{
newsCategorys=new ArrayList<HashMap<String, NewsCategoryEntity>>();
JSONArray newsList=dataObject.getJSONArray("info");
for (int i = 0; i < newsList.length(); i++) {
JSONObject newsObject=(JSONObject)newsList.opt(i);
HashMap<String, NewsCategoryEntity>news=new HashMap<String, NewsCategoryEntity>();
NewsCategoryEntity entity=new NewsCategoryEntity(newsObject.getInt("cid"), newsObject.getString("title"), 0);
news.put("category_title", entity);
newsCategorys.add(news);
}
}
}
return newsCategorys;
}
Java Json数据解析
最新推荐文章于 2022-11-28 19:51:52 发布