Andorid Json解析大全
2016-05-05 10:11
555 查看
1.使用Jackson 框架,轻易转换JSON:
详解:/article/4791847.html
示例:
try {
ObjectMapper objectMapper = new ObjectMapper();
StringWriter sw = new StringWriter();
JsonGenerator generator = objectMapper.getJsonFactory().createJsonGenerator(sw);
generator.writeObject(new Person(1, “tom” ,20));
generator.close();
return sw.toString();
} catch (IOException e) {
e.printStackTrace();
}
2.使用Gson框架
详解:/article/2227837.html
3.Android系统自带的
详解:/article/4791847.html
示例:
try {
ObjectMapper objectMapper = new ObjectMapper();
StringWriter sw = new StringWriter();
JsonGenerator generator = objectMapper.getJsonFactory().createJsonGenerator(sw);
generator.writeObject(new Person(1, “tom” ,20));
generator.close();
return sw.toString();
} catch (IOException e) {
e.printStackTrace();
}
2.使用Gson框架
详解:/article/2227837.html
3.Android系统自带的
public List<Area> getRemoteAreas(String keyword) throws Exception { List<Area> areaList = new ArrayList<Area>(); String returnValue = queryUtils.queryServer(keyword, "queryarea", "ServiceDocumentServlet"); if (returnValue != null && !"".equals(returnValue)) { JSONArray jsonArray = new JSONArray(returnValue); if (jsonArray != null) { JSONObject jsonObject; Area area = null; // 循环记录数(多少条) for (int i = 0; i < jsonArray.length(); i++) { area = new Area(); jsonObject = jsonArray.getJSONObject(i); if (jsonObject != null) { area.setId(jsonObject.getString("areaId")); area.setSname(jsonObject.getString("areaName")); area.setParent(jsonObject.getString("areaParent")); area.setpId(jsonObject.getString("areaPId")); areaList.add(area); } } } } return areaList; }
相关文章推荐
- js对联广告代码,兼容性高
- JSP不加载缓存
- 使用Gson解析复杂的json数据
- JavaScript-----判断Caps Lock是否开启
- js中正则表达式
- js中return false(阻止)的用法
- JavaScript权威指南 第七章 数组
- JavaScript中的类型转换
- javascript弹出对话框的几种形式
- JavaScript学习总结(三)——逻辑And运算符详解
- json
- JS FileReader对象
- JavaScript学习总结(二)——逻辑Not运算符详解
- JavaScript学习总结(一)——JavaScript基础
- 探讨:JavaScript ECAMScript5 新特性之get/set访问器
- js--异步编程的4种方法
- JS工作随笔04
- 浅析JS异步加载进度条
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
- 关于jsp、html重新加载后台html布局标签语言