java jsonarray string_String JSONObject JSONArray 转换
JSON使用阿里的fastJson为依赖包
gradle依赖管理如下:
compile group: ‘com.alibaba‘, name: ‘fastjson‘, version:‘1.2.41‘
1、String转JSONObject
前言:String 是JSONObject格式的字符串
eg:
JSONObject jSONObject = JSONObject.parseObject(String);
2、String转JSONArray
前言:String 是JSONArray格式的字符串
eg:
JSONArray jsonArray= JSONArray.parseArray(String);
3、JSONObject中的数组提取为JSONArray
eg:
{"AreaName": "北京","CityId": 110100,"NoMarket": false,"OldCityId": 646,"Pinyin": "beijing","ProvinceId": 110000,"Result": [
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "Stelvio 钜惠23.4万起","Url": "//www.autohome.com.cn/market/201904/100223763.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "马驹桥林肯中心年中大促","Url": "//www.autohome.com.cn/market/201906/100230932.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "星越平价销售13.58万元起","Url": "//www.autohome.com.cn/dealer/201906/367011492.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "哈弗F5限时优惠8000元","Url": "//www.autohome.com.cn/dealer/201906/366897778.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "购元新能源价格暂无优惠","Url": "//www.autohome.com.cn/dealer/201906/366897034.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "瑞虎3xe冰点价促销中!","Url": "//www.autohome.com.cn/dealer/201906/366889724.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "购奔奔EV现钜惠5.1万元","Url": "//www.autohome.com.cn/dealer/201906/366843204.html"},
{"ItemName": "优惠","ItemUrl": "/list/a646c12-1.html","Title": "购宝马7系价格暂无优惠","Url": "//www.autohome.com.cn/dealer/201906/366588080.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "途观L价格直降7.6万元","Url": "//www.autohome.com.cn/dealer/201906/366568937.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "购凯迪拉克XTS降8万","Url": "//www.autohome.com.cn/dealer/201906/366500646.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "汉兰达可试驾购车无优惠","Url": "//www.autohome.com.cn/dealer/201906/366384207.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "宝马M4价格稳定无优惠","Url": "//www.autohome.com.cn/dealer/201906/366156789.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "奥迪A8促销直降26.33万元","Url": "//www.autohome.com.cn/dealer/201906/366925378.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "英菲尼迪Q50L可降6.3万","Url": "//www.autohome.com.cn/dealer/201906/366863516.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "帝豪新能源价格降8.25万","Url": "//www.autohome.com.cn/dealer/201906/366877669.html"},
{"ItemName": "预定","ItemUrl": "/list/a646c14-1.html","Title": "撼路者在售现钜惠5万","Url": "//www.autohome.com.cn/dealer/201906/366912121.html"}
]
}
提取Result对应的数组
JSONArray jsonArray= jsonObject.getJSONArray("Result");
4、JSONArray提取为JSONObject
eg:
JSONObject jsonObject = jsonArray.getJSONObject(0);
5、JSONObject获取value
1、object.getString("key")2、object.get("key")
6、获取JSONObject的ket value
JSONArray dateArr = newJSONArray();
Set key =dateArr .keySet();for(String keyObj:key) {
JSONArray hisData=history.getJSONArray(keyObj);
}
7、遍历JSONArray
第一种for循环
JSONArray seriesArr= newJSONArray();for(int i=0;i
JSONObject object=eggsArr.getJSONObject(i);
}
第二种for增强
JSONArray pzListArr= newJSONArray();for(Object obj:pzListArr) {
JSONObject dataObj=JSONObject.parseObject(obj.toString());
}
8、javaBean转为JSONObject
未完待续······
java jsonarray string_String JSONObject JSONArray 转换相关推荐
- java object数组转实体类_详解Java中String JSONObject JSONArray List实体类转换
JSON使用阿里的fastJson为依赖包 gradle依赖管理如下: compile group: "com.alibaba", name: "fastjson&quo ...
- fastjson中JSONArray和JSONObject
1 什么是JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于javascript Prog ...
- java清空json_java – 从JSONArray中删除JSON对象 – Jettison
是否有通过使用索引删除存储在JSONArray中的JSONObject的直接方法.我尝试了所有的可能性.仍然无法从JSON数组中删除JSON对象.任何提示都会有所帮助 谢谢 解决方法: 在java-j ...
- 对象转数组_fastJson中java对象 jsonObject jsonArray之间转换
一.介绍 简介:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式 二.使用 1.java对象转jsonObject User u = new User(); ...
- java jsonarray 包,JSONObject与JSONArray的使用
1.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: 1.commons-lang.jar 2.commons-beanutils.jar 3.c ...
- 解决嵌套list类型的JSONObject/JSONArray转换成原来list问题。
解决嵌套list类型的JSONObject/JSONArray转换成原来list问题. 参考文章: (1)解决嵌套list类型的JSONObject/JSONArray转换成原来list问题. (2) ...
- java JSONArray与JSONObject的增删改查大解析 一篇让你不再迷茫
前提 相关的jar包 https://download.csdn.net/download/qq_37591637/11162911 JSONArray与JSONObject的区别 JSONArr ...
- JSONObject JSONArray各种用法以及js eval()函数与JSON.parse的区
2019独角兽企业重金招聘Python工程师标准>>> 一.在后台使用JSONObject对象,并将从数据库中取出来的数据直接使用 JSONObject的put方法放进去,再将这个J ...
- Android开发将List转化为JsonArray和JsonObject
客户端需要将List<Object>转化为JsonArray和JsonObject的方法: 首先,List中的Object的属性需要是public: class Person {publi ...
- Java 语言 ArrayList 和 JSONArray 相互转换
Student 实体类 /*** @author Miracle Luna* @version 1.0* @date 2019/7/5 18:06*/ public class Student {pr ...
最新文章
- tornado压力测试
- 基于php下载文件的详解
- 查看历史操作记录_燕麦课堂丨操作日志管理,为企业数据安全保驾护航
- 怎么解决深入学习PHP的瓶颈?
- linux内核唤醒过程,Linux内核启动过程分析
- python 中 property 属性的讲解及应用
- css --- 应用媒介查询制作响应式导航栏
- LF模式是个坑,ZeroIce中间件让你体会这个痛
- 阿里第二代微服务强势崛起,你还敢往简历上写“精通”吗?
- 漫画:分布式缓存服务器扛不住了怎么办?| 技术头条
- APUE学习笔记:第五章 标准I/O库
- 前端学习笔记系列一:1.export default / export const
- 推荐一款配置中心新贵:Nacos,阿里开源,是真的香!!
- MOSS Visual How To 系列
- Windows目录下SysWow64文件夹与System32文件夹
- Python中神奇的第三方库:Faker假数据生成器
- 为什么 React17-rc.2 要发布新的 jsx 转换逻辑
- 基于JAVA的葫芦娃救爷爷游戏
- VLC2.2.4命令参数
- 力扣 (LeetCode)-对称二叉树,树|刷题打卡
热门文章
- SQL 删除重复记录,并保留其中一条
- nrf51822微信开发入门学习笔记1:开始前的准备
- FastJson(阿里巴巴)基础
- iOS开发之SQLite的Object-C封装
- [学习日记] 文件读写 FileStream
- MaxEnt: 最大熵模型(Maximum Entropy Models)(二)
- C/C++变量在内存中的分布
- 教育局查询2021年高考成绩,关于广东省2021年普通高考英语听说考试成绩发布有关事宜的通知...
- 连锁加盟网站源码_连锁60秒:招商只是开始,养商才最重要
- java编程_Java最热常用编程软件分享