复杂json的解析:jsonobject与jsonArray的使用
String parameter = {
success : 0,
errorMsg : "错误消息",
data : {
total : "总记录数",
rows : [ {
id : "任务ID",
workName : "任务名称",
assigneeName : "经办人姓名",
name : "流程步骤名称",
processInstanceInitiatorName : "发起人",
processInstanceStartTime : "发起时间",
createTime : "到达时间",
dueDate : "截止时间"
}, {
id : "ID",
workName : "名称",
assigneeName : "经办人",
name : "流程",
processInstanceInitiatorName : "发起人",
processInstanceStartTime : "发起",
createTime : "到达",
dueDate : "截止"
} ]
}
};
JSONObject jsonObject =JSONObject.fromObject(parameter);
System.out.println("success:"+jsonObject.get("success"));
System.out.println("errorMsg:"+jsonObject.get("errorMsg"));
System.err.println("total:"+jsonObject.getJSONObject("data").get("total"));
JSONObject data = jsonObject.getJSONObject("data");
JSONArray jsonArray = data.getJSONArray("row");
JSONObject row = null;
for (int i = 0; i < jsonArray.size(); i++) {
row = jsonArray.getJSONObject(i);
System.out.println("id:"+row.get("id"));
System.out.println("workName:"+row.get("workName"));
System.out.println("assigneeName:"+row.get("assigneeName"));
System.out.println("name:"+row.get("name"));
System.out.println("processInstanceInitiatorName:"+row.get("processInstanceInitiatorName"));
System.out.println("processInstanceStartTime:"+row.get("processInstanceStartTime"));
System.out.println("createTime:"+row.get("createTime"));
System.out.println("dueDate:"+row.get("dueDate"));
}
复杂json的解析:jsonobject与jsonArray的使用的更多相关文章
- Android 解析JSONObject以及JSONArray对比
在Android客户端与服务器交互的过程中,客户端一般采用json解析服务器的返回数据.此时有两种数据格式.但其根本都是字符串或字符串数组! 1.JSONObject 下面是PHP端代码: <? ...
- Gson解析JsonObject和JsonArray
Gson中重要的几个核心类: Gson.JsonParser.JsonObject.JsonArray. 下面就是解析的步骤: public void parserJsonArray(String s ...
- Fastjson, Gson, org.json.JSON三者对于JSONObject及JSONArray的判断
1.Fastjson 我们通常在已知格式的情况下直接使用JSONObject,JSONArray,但是如果遇到需要判断格式呢? try{ Object object = JSON.parse(a); ...
- Java之JSON处理(JSONObject、JSONArray)
依赖包:json-20180130.jar MAVEN地址: <dependency> <groupId>org.json</groupId> <artifa ...
- json字符串转JSONObject和JSONArray以及取值
import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class JsonTest { public static v ...
- json字符串转换为JSONObject和JSONArray
一.下载json 具体到http://www.json.org/上找java-json下载,并把其放到项目源代码中,这样就可以引用其类对象了 二.具体转化过程 //JSONObject String ...
- [转] json字符串转换为JSONObject和JSONArray
一.下载json 具体到http://www.json.org/上找java-json下载,并把其放到项目源代码中,这样就可以引用其类对象了 二.具体转化过程 //JSONObject String ...
- 使用Gson轻松解决复杂结构的Json数据解析
转载请注明来源: http://blog.csdn.net/kjunchen/article/details/50961803 JSON简介 JSON(JavaScript Object Notati ...
- [转]java中JSONObject与JSONArray的使用详细说明及有关JSON的工具类
JSONObject与JSONArray的使用 一.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: 1.commons-lang.jar 2.c ...
- 011-JSON、JSONObject、JSONArray使用、JSON数组形式字符串转换为List<Map<String,String>>的8种方法
一.JSON数据格式 1.1.常用JSON数据格式 1.对象方式:JSONObject的数据是用 { } 来表示的, 例如: { "id" : "123", & ...
随机推荐
- Netty 接受请求过程源码分析 (基于4.1.23)
前言 在前文中,我们分析了服务器是如何启动的.而服务器启动后肯定是要接受客户端请求并返回客户端想要的信息的,否则要你服务器干啥子呢?所以,我们今天就分析分析 Netty 在启动之后是如何接受客户端请求 ...
- webpack3新特性简介
6月20号webpack推出了3.0版本,官方也发布了公告.根据公告介绍,webpack团队将未来版本的改动聚焦在社区提出的功能需求,同时将保持一个快速.稳定的发布节奏.本文主要依据公告内容,简单介绍 ...
- Spring基础(3) : 静态工厂和实例工厂创建bean
public class Factory { public static Person staticCreate(){ Person p = new Person(); p.name="st ...
- VS比较好用的扩展插件总结
1.Indent Guides 绝对是必须的,有了这些辅助线,代码结构一目了然. 2.CodeMaid 整理与优化代码,并且可以清除空行.必备 把if语句块for语句块折叠 工具->扩展和更新, ...
- 【RabbitMQ】1、RabbitMQ的几种典型使用场景
RabbitMQ主页:https://www.rabbitmq.com/ AMQP AMQP协议是一个高级抽象层消息通信协议,RabbitMQ是AMQP协议的实现.它主要包括以下组件: 1.Serve ...
- 两车追及或相遇问题(hdu1275)数学题
两车追及或相遇问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 不依赖AIDL的跨进程通信
http://blog.csdn.net/lmj623565791/article/details/38461079 如果知道AIDL和binder的原理,可以简单写一个不依赖AIDL的跨进程通信 不 ...
- Textview源码+绘制过程解析
Android控件TextView的实现原理分析 为什么要规定所有与UI相关的操作都必须在主线程中执行呢?我们知道,这些与UI相关的操作都涉及到大量的控件内部状态以及需要访问窗口的绘图表面,也就是说, ...
- hadoop的namenode故障处理方法
Namenode 故障后,可以采用如下两种方法恢复数据. 方法一:将 SecondaryNameNode 中数据拷贝到 namenode 存储数据的目录: 方法 二: 使用 -importCheckp ...
- php魔术方法__tostring的应用
当echo一个对象的时候,会报错误 Object of class Person could not be converted to string 我们可以通过魔术方法__tostring() 把对 ...