JSON解析
来源:互联网 发布:sql语句大全实例教程 编辑:程序博客网 时间:2024/06/08 03:15
package com.lingzhuo.jsontest;import net.sf.json.JSONArray;import net.sf.json.JSONObject;public class JSONTest { public static void main(String[] args) { String json = CreatJSON(); JSONObject obj = JSONObject.fromObject(json); System.out.println(obj.getString("city"));// System.out.println(obj.getString("today")); JSONObject today = obj.getJSONObject("today"); JSONArray array = today.getJSONArray("index"); for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); System.out.println(object.getString("name")); } } private static String CreatJSON() { JSONObject obj=new JSONObject(); obj.put("city","北京"); obj.put("cityid", "123"); JSONObject today=new JSONObject(); today.put("date", "2015-08-03"); today.put("week", "星期一"); JSONArray array=new JSONArray(); JSONObject index1=new JSONObject(); index1.put("name", "感冒"); JSONObject index2=new JSONObject(); index2.put("name", "防晒"); JSONObject index3=new JSONObject(); index3.put("name", "炎热"); array.add(index1); array.add(index2); array.add(index3); today.put("index", array); obj.put("today", today);// System.out.println(obj.toString()); return obj.toString(); }}
0 0
- 【JSON解析】JSON解析
- 解析JSON
- Json解析
- JSON解析
- JSON解析
- json解析
- Json解析
- Json解析
- JSON解析
- Json解析
- Json解析
- JSON解析
- JSON解析
- json 解析
- Json解析
- JSON解析
- json解析
- json 解析
- php能把函数名作为参数传递吗?
- Java之正则表达式验证手机号码
- 反转一个单向链表
- redis功能丰富
- 当心从10亿估值沦落到一无所获!创业者签订融资协议时该注意什么?
- JSON解析
- python常用方法
- leetcode_Rectangle Area
- NSOperation与GCD区别,更新UI的3种方式
- python常用字符串操作
- 虚拟主机三种实现方式Apache
- 利用Python分析GP服务运行结果的输出路径 & 实现服务输出路径的本地化
- Java之String类
- HDU 5363 Key Set(快速幂)