Gson解析复杂JSON对象
2015-01-08 10:58
344 查看
例如以下格式JSON:
建立对应的Java对象,注意内部类要定义成静态的
使用Gson进行解析
运行结果:
建立对应的Java对象,注意内部类要定义成静态的
public class HResult { public String total; public String records; public String page; public List<HCell> rows; static class HCell{ public List<String> cell; public String id; } }
使用Gson进行解析
public static void main(String[] args) { String json = "{\"total\":\"1\",\"rows\":[{\"cell\":[\"c1\",\"c2\",\"没有检索到相关历史信息,请点击[我要留言]\",\"c4\",\"c5\",\"c6\",\"c7\"],\"id\":\"999999999999999999999999999999\"}],\"records\":\"0\",\"page\":\"1\"}"; Gson gson = new Gson(); HResult hResult = gson.fromJson(json, new TypeToken<HResult>(){}.getType()); System.out.println("total:"+hResult.total); System.out.println("records:"+hResult.records); System.out.println("page:"+hResult.page); List<HResult.HCell> list = hResult.rows; for(HResult.HCell row:list){ System.out.println("cell:"+row.cell); System.out.println("id:"+row.id); } }
运行结果:
run: total:1 records:0 page:1 cell:[c1, c2, 没有检索到相关历史信息,请点击[我要留言], c4, c5, c6, c7] id:999999999999999999999999999999 成功构建 (总时间: 0 秒)
相关文章推荐
- Gson解析复杂Json数据
- 使用GSON解析复杂的JSON数据(有DEMO)
- 用Gson解析复杂的天气Json数据
- Java解析Json字符串--复杂对象
- Gson解析Json和将对象生成Json
- 使用Gson解析复杂的json数据
- 以淘宝详情页面Json为例使用Gson的JsonReader解析复杂Json数据详解
- gson解析复杂的json
- Gson解析复杂的json数据
- Gson解析复杂的json数据
- 使用Gson解析复杂、变态的Json数据(包含中文key)
- 如何利用.Net内置类,解析未知复杂Json对象
- 百度天气api开发 全解析xml和json格式 使用json-lib jsonObject、 Gson 方式把json 转换成 java对象
- Gson 解析复杂json字符串
- GSON解析复杂json数据格式
- Gson解析简单json以及复杂的json数据
- 使用Gson解析复杂的json数据
- Json数据解析----------Gson用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库
- Gson解析json字符串、json数组转换成对象
- 【Android】Gson-以类模板的方式解析复杂JSON