Fastjson是阿里巴巴公司开源的速度最快的Json和对象转换工具,一个Java语言编写的JSON处理器。
1、遵循http://json.org标准,为其官方网站收录的参考实现之一。
2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。
3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。
4、开源,使用Apache License 2.0协议开源。http://code.alibabatech.com/wiki/display/FastJSON/Home
2、主要的使用入口
public static final JSONObject parseObject(String text); // 把JSON文本parse成JSONObject
public static final <T> T parseObject(String text, Class<T> clazz); // 把JSON文本parse为JavaBean
public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray
public static final <T> List<T> parseArray(String text, Class<T> clazz); //把JSON文本parse成JavaBean集合
public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本
public static final String toJSONString(Object object, boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本
public static final Object toJSON(Object javaObject); //将JavaBean转换为JSONObject或者JSONArray。
JSONObject json = JSON.parseObject(resultScheduleRedis);
JSONArray jsonArrayResultRedis = JSONArray.parseArray(String.valueOf(json.get("result")));
json转 对象
ScheduleDTO resultDTO = JSON.parseObject(json.toJSONString(), new TypeReference<ScheduleDTO>() {});
//**************************************************
3、有关类库的一些说明
SerializeWriter:相当于StringBuffer
JSONArray:相当于List<Object>
JSONObject:相当于Map<String, Object>
JSON反序列化没有真正数组,本质类型都是List<Object>
、fastjson还有很多很高级的特性,比如支持注解、支持全类型序列化,这些都是很好的特性,功能强大,不再讲解。
这是关于FastJson的一个使用Demo,在Java环境下验证的
- class User{
- private int id;
- private String name;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
*******************************************************************************************************************************************
- import java.util.ArrayList;
- import java.util.List;
- class Group{
- private int id;
- private String name;
- private List<User> list = new ArrayList<User>();
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public List<User> getList() {
- return list;
- }
- public void setList(List<User> list) {
- this.list = list;
- }
- }
******************************************************************************************************************************************************************
- lass Weibo {
- private String id;
- private String city;
- public Weibo(String id, String city) {
- this.id = id;
- this.city = city;
- }
- public Weibo() {
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this.city = city;
- }
- }
******************************************************************************************************************************************************************
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- /**
- * 这是关于FastJson的一个使用Demo,在Java环境下验证的;
- * 使用的时候可以参照这个例子进行回忆!
- * 备注:下面写的Json格式的数据"前面的\,意思是告诉编译器忽略掉它后面的"。
- * 后面定义有三个类:User、Group、Weibo
- * @author liuzhao
- */
- public class JsonDemo {
- public static void main(String[] args) {
- json2JsonObjectM1();//将Json文本数据信息转换为JsonObject对象,然后利用键值对的方式获取信息
- json2BeanM2();//将Json文本数据转换为JavaBean数据!
- json2JSONArrayM3();//将json数据转化为JSONArray:
- json2JavaBeanM4();//将JSON文本转换为JavaBean的集合;转换为单纯的1个Object:parseObject(String text, Class<T> clazz);
- bean2JsonM5();//将JavaBean转换为Json格式的数据/Json文本 用户数据的传递:例如上传服务器
- bean2JSONObjectM6();//将JavaBean转换为JSON对象
- complexExampleM7();//一个相对复杂的例子:
- complex2JsonM8();//一个复杂的Object到Json的Demo
- complexMap2JsonM9();//将Map数据转换为JsonString的Demo;这个对RedBoy服务端不就直接破了嘛!
- }
- /**
- * 将Json文本数据信息转换为JsonObject对象,然后利用键值对的方式获取信息
- */
- private static void json2JsonObjectM1() {
- //一个JsonObject文本数据
- String s = "{\"name\":\"liuzhao\"}";
- //将JsonObject数据转换为Json
- JSONObject object = JSON.parseObject(s);
- //利用键值对的方式获取到值
- System.out.println(object.get("name"));
- /**
- * 打印:
- * liuzhao
- */
- }
- /**
- * 将Json文本数据转换为JavaBean数据!
- * 需要注意的是:这时候的Json文本信息中的键的名称必须和JavaBean中的字段名称一样!键中没有的在这个JavaBean中就显示为null!
- */
- private static void json2BeanM2() {
- String s = "{\"id\":\"0375\",\"city\":\"平顶山\"}";
- //一个简单方便 的方法将Json文本信息转换为JsonObject对象的同时转换为JavaBean对象!
- Weibo weibo = JSON.parseObject(s, Weibo.class);//Weibo类在下边定义
- System.out.println(weibo.getId());
- System.out.println(weibo.getCity());
- //打印的结果 0375
- // 平顶山
- }
- /**
- * 将Map类型的数据转换为JsonString
- */
- private static void complexMap2JsonM9() {
- Group group = new Group();
- group.setId(1);
- group.setName("group");
- User user1 = new User();
- user1.setId(2);
- user1.setName("user1");
- User user2 = new User();
- user2.setId(3);
- user2.setName("user2");
- group.getList().add(user1);
- group.getList().add(user2);
- Map<Integer, Object> map = new HashMap<Integer,Object>();
- map.put(1, "No.1");
- map.put(2, "No.2");
- map.put(3, group.getList());
- String jsonString = JSON.toJSONString(map);
- System.out.println(jsonString);
- /**
- * 输出:{1:"No.1",2:"No.2",3:[{"id":2,"name":"user1"},{"id":3,"name":"user2"}]}
- */
- }
- /**
- * 由一个复杂的Object到Json的Demo
- */
- private static void complex2JsonM8() {
- Group group = new Group();
- group.setId(1);
- group.setName("group");
- User user1 = new User();
- user1.setId(2);
- user1.setName("user1");
- User user2 = new User();
- user2.setId(3);
- user2.setName("user2");
- group.getList().add(user1);
- group.getList().add(user2);
- String jsonString = JSON.toJSONString(group);
- System.out.println(jsonString);
- /**
- * 输出:{"id":1,"list":[{"id":2,"name":"user1"},{"id":3,"name":"user2"}],"name":"group"}
- */
- }
- /**
- * 一个相对复杂的例子:
- * JSON文本数据:
- * 首先是JSONObject,转换为JSONArray;
- * 然后将JSONArray转换为JavaBean
- */
- private static void complexExampleM7() {
- String s = "{js:[{id:\"110000\",\"city\":\"北#001京市\"},{id:\"110000\",\"city\":\"北#002京市\"}"
- + ",{id:\"110000\",\"city\":\"北#002京市\"},{id:\"110000\",\"city\":\"北#002京市\"},"
- + "{id:\"110000\",\"city\":\"#006北#005京市\"},"
- + "{id:\"110000\",\"city\":\"北#002京市\"},"
- + "{id:\"110000\",\"city\":\"北#002京市\"},{id:\"120000\",\"city\":\"天#009津市\"}]}";
- JSONObject object = JSON.parseObject(s);
- Object jsonArray = object.get("js");
- System.out.println(jsonArray);
- List<Weibo> list = JSON.parseArray(jsonArray+"", Weibo.class);
- for (Weibo weibo : list) {
- System.out.println(weibo.getCity());
- }
- }
- /**
- * 将JavaBean转换为JSON对象
- */
- private static void bean2JSONObjectM6() {
- Weibo weibo = new Weibo("0373", "洛阳");
- JSONObject json = (JSONObject) JSON.toJSON(weibo);
- System.out.println(json.get("id"));
- /**
- * 打印:
- * 0373
- */
- }
- /**
- * 将JSON文本转换为JavaBean的集合;
- * 内部实现肯定是:首先转换为JSONArray,然后再转换为List集合
- */
- private static void json2JavaBeanM4() {
- String s = "[{\"id\":\"0375\",\"city\":\"平顶山\"},{\"id\":\"0377\",\"city\":\"南阳\"}]";
- List<Weibo> list = JSON.parseArray(s, Weibo.class);
- for (Weibo weibo : list) {
- System.out.println(weibo.getCity());
- }
- /**
- * 打印:
- * 平顶山
- * 南阳
- */
- }
- /**
- * 将json数据转化为JSONArray:
- * 注意:获取到JSONArray之后(我们这里只是获取到JSONArray而不是JavaBean的List集合)
- * 获取JSONArray中的数据转换为String类型需要在外边加"";
- */
- private static void json2JSONArrayM3() {
- String s = "[{\"id\":\"0375\",\"city\":\"平顶山\"},{\"id\":\"0377\",\"city\":\"南阳\"}]";
- //将JSON文本转换为JSONArray
- JSONArray array = JSON.parseArray(s);
- //这行必须写:必须加上+"";不然会报出类型强转异常!
- String str = array.get(1)+"";
- System.out.println(array.get(0));
- JSONObject object = JSON.parseObject(str);
- System.out.println(object.get("id"));
- /**
- * {"city":"平顶山","id":"0375"}
- 0377
- */
- }
- /**
- * 将JavaBean转换为Json格式的数据/Json文本
- * 用户数据的传递:例如上传服务器
- */
- private static void bean2JsonM5() {
- Weibo weibo = new Weibo("123456", "上海");
- String string = JSON.toJSONString(weibo);
- System.out.println(string);
- /**
- * 打印:
- * {"city":"上海","id":"123456"}
- */
- }
- }
如下:
JSON数据:
{
"result":{
"result":[
{
"countlist":[
],
"list":[
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000388201909249814243211",
"tradeState":"SUCCESS",
"tradeTime":"2019-09-24 16:17:23",
"totalFee":"0.01",
"rate":"0.60",
"outTradeNo":"20190924161701",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000377201909248262354118",
"tradeState":"SUCCESS",
"tradeTime":"2019-09-24 15:41:25",
"totalFee":"0.01",
"rate":"0.60",
"outTradeNo":"20190924154110",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000396201909248111329354",
"tradeState":"SUCCESS",
"tradeTime":"2019-09-24 16:18:59",
"totalFee":"0.01",
"rate":"0.60",
"outTradeNo":"20190924161846",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000392201909249461361494",
"tradeState":"SUCCESS",
"tradeTime":"2019-09-24 15:36:41",
"totalFee":"0.01",
"rate":"0.60",
"outTradeNo":"20190924153625",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"QDCCB_DEBIT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000386201909245289806801",
"tradeState":"SUCCESS",
"tradeTime":"2019-09-24 09:05:55",
"totalFee":"0.01",
"rate":"0.60",
"outTradeNo":"20190924090524",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000388201909249814243211",
"tradeState":"REFUND",
"tradeTime":"2019-09-24 16:27:29",
"totalFee":"0.00",
"rate":"0.60",
"outTradeNo":"20190924161701",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"QDCCB_DEBIT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000373201909230181672212",
"tradeState":"REFUND",
"tradeTime":"2019-09-24 15:09:03",
"totalFee":"0.00",
"rate":"0.60",
"outTradeNo":"20190923172817",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000377201909248262354118",
"tradeState":"REFUND",
"tradeTime":"2019-09-24 17:15:43",
"totalFee":"0.00",
"rate":"0.60",
"outTradeNo":"20190924154110",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
},
{
"serviceFee":"0.00",
"mchId":"1493912972",
"equipment_code":"",
"bankType":"CFT",
"discount":"0.00",
"subMchId":"1556008101",
"feeType":"CNY",
"transactionId":"4200000396201909248111329354",
"tradeState":"REFUND",
"tradeTime":"2019-09-24 16:31:29",
"totalFee":"0.00",
"rate":"0.60",
"outTradeNo":"20190924161846",
"goodsName":"测试商品1",
"tradeType":"FACEPAY"
}
]
}
],
"total":9,
"pageSize":0,
"pageNum":0
},
"success":true,
"error":""
}
解析:
//阿里巴巴 JSON字符串转JSONObject对象
JSONObject jsonObject = JSON.parseObject(a);
System.err.println("阿里巴巴 JSON字符串转JSONObject对象"+jsonObject);
//获取到 属性"result" 转换成对象
JSONObject jsonObject1 = JSON.parseObject(jsonObject.get("result").toString());
System.err.println("获取到 属性\"result\" 转换成对象"+jsonObject1);
// 获取到 属性"result" 转换成数组
JSONArray parseArray = JSON.parseArray(jsonObject1.get("result").toString());
System.err.println("获取到 属性\"result\" 转换成数组"+parseArray);
// 数组转对象
JSONObject jsonObject2 = JSON.parseObject(parseArray.get(0).toString());
System.err.println("数组转对象"+jsonObject2);
//获取到 "list" 转换成 数组
JSONArray jsonArray = JSON.parseArray(jsonObject2.get("list").toString());
System.err.println("获取到 \"list\" 转换成 数组"+jsonArray);
//遍历数组
for (int i = 0; i <jsonArray.size() ; i++) {
//找到具体的值
System.err.println(jsonArray.getJSONObject(i).get("mchId"));
}
打印结果:
阿里巴巴 JSON字符串转JSONObject对象:{"result":{"result":[{"countlist":[],"list":[{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:17:23","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:41:25","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:18:59","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000392201909249461361494","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:36:41","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924153625","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000386201909245289806801","tradeState":"SUCCESS","tradeTime":"2019-09-24 09:05:55","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924090524","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"REFUND","tradeTime":"2019-09-24 16:27:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000373201909230181672212","tradeState":"REFUND","tradeTime":"2019-09-24 15:09:03","totalFee":"0.00","rate":"0.60","outTradeNo":"20190923172817","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"REFUND","tradeTime":"2019-09-24 17:15:43","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"REFUND","tradeTime":"2019-09-24 16:31:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"}]}],"total":9,"pageSize":0,"pageNum":0},"success":true,"error":""}
获取到 属性"result" 转换成对象:{"result":[{"countlist":[],"list":[{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:17:23","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:41:25","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:18:59","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000392201909249461361494","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:36:41","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924153625","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000386201909245289806801","tradeState":"SUCCESS","tradeTime":"2019-09-24 09:05:55","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924090524","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"REFUND","tradeTime":"2019-09-24 16:27:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000373201909230181672212","tradeState":"REFUND","tradeTime":"2019-09-24 15:09:03","totalFee":"0.00","rate":"0.60","outTradeNo":"20190923172817","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"REFUND","tradeTime":"2019-09-24 17:15:43","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"REFUND","tradeTime":"2019-09-24 16:31:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"}]}],"total":9,"pageSize":0,"pageNum":0}
获取到 属性"result" 转换成数组:[{"countlist":[],"list":[{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:17:23","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:41:25","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:18:59","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000392201909249461361494","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:36:41","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924153625","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000386201909245289806801","tradeState":"SUCCESS","tradeTime":"2019-09-24 09:05:55","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924090524","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"REFUND","tradeTime":"2019-09-24 16:27:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000373201909230181672212","tradeState":"REFUND","tradeTime":"2019-09-24 15:09:03","totalFee":"0.00","rate":"0.60","outTradeNo":"20190923172817","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"REFUND","tradeTime":"2019-09-24 17:15:43","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"REFUND","tradeTime":"2019-09-24 16:31:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"}]}]
数组转对象:{"countlist":[],"list":[{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:17:23","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:41:25","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:18:59","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000392201909249461361494","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:36:41","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924153625","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000386201909245289806801","tradeState":"SUCCESS","tradeTime":"2019-09-24 09:05:55","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924090524","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"REFUND","tradeTime":"2019-09-24 16:27:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000373201909230181672212","tradeState":"REFUND","tradeTime":"2019-09-24 15:09:03","totalFee":"0.00","rate":"0.60","outTradeNo":"20190923172817","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"REFUND","tradeTime":"2019-09-24 17:15:43","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"REFUND","tradeTime":"2019-09-24 16:31:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"}]}
获取到 "list" 转换成 数组:[{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:17:23","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:41:25","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"SUCCESS","tradeTime":"2019-09-24 16:18:59","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000392201909249461361494","tradeState":"SUCCESS","tradeTime":"2019-09-24 15:36:41","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924153625","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000386201909245289806801","tradeState":"SUCCESS","tradeTime":"2019-09-24 09:05:55","totalFee":"0.01","rate":"0.60","outTradeNo":"20190924090524","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000388201909249814243211","tradeState":"REFUND","tradeTime":"2019-09-24 16:27:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161701","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"QDCCB_DEBIT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000373201909230181672212","tradeState":"REFUND","tradeTime":"2019-09-24 15:09:03","totalFee":"0.00","rate":"0.60","outTradeNo":"20190923172817","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000377201909248262354118","tradeState":"REFUND","tradeTime":"2019-09-24 17:15:43","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924154110","goodsName":"测试商品1","tradeType":"FACEPAY"},{"serviceFee":"0.00","mchId":"1493912972","equipment_code":"","bankType":"CFT","discount":"0.00","subMchId":"1556008101","feeType":"CNY","transactionId":"4200000396201909248111329354","tradeState":"REFUND","tradeTime":"2019-09-24 16:31:29","totalFee":"0.00","rate":"0.60","outTradeNo":"20190924161846","goodsName":"测试商品1","tradeType":"FACEPAY"}]
1493912972
1493912972
1493912972
1493912972
1493912972
1493912972
1493912972
1493912972
1493912972
------------------------------------------------------------
{
"data":{
"landing_page_id":10000,
"url":"https://pages.xiaohongshu.com/ad/effect/test",
"submitted_time":"2019-10-15 13:19:45",
"source_channel":"信息流",
"account_id":"5afbb4c54eacab482919dcb2",
"account_name":"薯管家",
"campaign_id":10000,
"campaign_name":"测试计划",
"unit_id":10000,
"unit_name":"测试单元",
"creative_id":10000,
"leads_id":"5da556f1ef7569c2434cd3b8",
"data":[
{
"label":"姓名",
"value":"薯管家"
},
{
"label":"手机号",
"value":"123xxxxxxxx"
},
{
"label":"邮箱",
"value":"test@xiaohongshu.com"
},
{
"label":"省份",
"value":"上海"
},
{
"label":"城市",
"value":"上海市"
},
{
"label":"详细地址",
"value":"xxx"
},
{
"label":"性别",
"value":"男"
},
{
"label":"数值",
"value":"515"
},
{
"label":"多选",
"value":"[\"选项 2\",\"选项 1\",\"选项 3\"]"
},
{
"label":"文本",
"value":"123abc"
},
{
"label":"单选",
"value":"选项 3"
}
]
},
"timestamp":1571116785851,
"source":"小红书"
}
JSONObject parseObject = JSON.parseObject(json);
System.err.println(parseObject);
JSONObject data = parseObject.getJSONObject("data");
System.err.println(data);
JSONArray data1 = data.getJSONArray("data");
System.err.println(data1);
for (int i = 0; i < data1.size(); i++) {
System.out.println(data1.getJSONObject(i).get("label"));
}