json解析
来源:互联网 发布:ant java版本 编辑:程序博客网 时间:2024/05/01 21:00
解析技巧:见到大括号 就用JsonObject ,见到中括号就是JsonArray
要解析的json文件
{ "phone" : ["123", "234"], // 数组 "name" : "xiao", // 字符串 "address" : { "country" : "china", "province" : "jiangsu" }, // 对象 "married" : true // 布尔值 "age" : 100, // 数值 }生成json文件
try { //大括号就用JSONObject() JSONObject person = new JSONObject(); // 第一个键phone的值是数组,所以需要创建数组对象 JSONArray phone = new JSONArray(); phone.put("123").put("234"); person.put("phone", phone); person.put("name",xiao<span style="font-family: Arial, Helvetica, sans-serif;">"); </span> // 键address的值是对象,所以又要创建一个对象 JSONObject address = new JSONObject(); address.put("country", "china"); address.put("province", "guangdong"); person.put("address", address); person.put("married", true); person.put("age", 100); } catch (JSONException ex) { throw new RuntimeException(ex); }解析json文件
try { private Long[] a; JSONObject person = new JSONObject(); JSONArray jsonArray= persongetJSONArray("phone")for(int i=0;i<jsonArray.length();i++){Long a[i]=jsonArray.getLong(i)} person.getString("name"); JSONObject address=JSONObject().get("address") address getString("country"); address getString("province"); person.getLong("married"); person.getString("age"); } catch (JSONException ex) { throw new RuntimeException(ex); }
0 0
- 【JSON解析】JSON解析
- 解析JSON
- Json解析
- JSON解析
- JSON解析
- json解析
- Json解析
- Json解析
- JSON解析
- Json解析
- Json解析
- JSON解析
- JSON解析
- json 解析
- Json解析
- JSON解析
- json解析
- json 解析
- nginx重启
- 针对开发者的20款移动开发框架
- Android源代码结构分析
- 按各字符的ASCII码从小到大的顺序输出字符
- HDOJ 1013 Digital Roots
- json解析
- 设计模式之解释器模式
- JMS与ActiveMQ
- async不得不说的事:SynchronizationContext
- 研究生第四课 计算机网络
- C经典 宏与typedef的区别
- math.h简介
- 单元测试JUnit
- 对象序列化输出 Serializable