请教一个利用Gson解析Json格式的问题

snbill 2012-06-13 08:01:31

这种格式的Json文件如何用Gson解析?

{"info":[{"id":"001","name":"001","cd":"10","state":0,"time":"30"},{"id":"002","name":"002","cd":"10","state":0,"time":"30"},{"id":"003","name":"003","cd":"10","state":0,"time":"30"},{"id":"004","name":"004","cd":"10","state":0,"time":"30"}],"Zongyeshu":3,"Dangqianye":1,"Shuliang":3,"Zongshu":23}
...全文
118 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sligner 2012-06-14
  • 打赏
  • 举报
回复
从服务器得到json字符串之后,用android提供的jsonObject和jsonArray处理

JSONObject resultJson=new JSONObject(strBuff.toString());
JSONArray infos = resultJson.getJSONArray("info");
for(int i = 0;i<infos.length();i++){
JSONObject info = (JSONObject)infos.get(i);
info.getString("id");
info.getString("cd");
}
snbill 2012-06-13
  • 打赏
  • 举报
回复

String abc = "\"Zongyeshu\":3,\"Dangqianye\":1,\"Shuliang\":3,\"Zongshu\":23}";
String tempA[]=abc.split(",");
String tempB[]=tempA[0].split(":");
int Zongyeshu=Integer.valueOf(tempB[1]);
System.out.println("得到的总页数为:"+Zongyeshu);

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧