Java有很多包能用来对json进行各种操作,包括:
因为我知识积累较少,只了解一些FastJson,这里我就以FastJson来写
环境(maven):
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
json对象的使用方法
在引入了fastjson的包之后,能够得到一种类“ JSONObject”,实例化之后称为json对象
JSONObject object = JSONObject.parseObject({\"boolean\":true,\"string\":\"string\",\"list\":[1,2,3],\"int\":2}");
//string
json字符串—>json对象
JSON.parseObject() 从字符串解析 JSON 对象
JSON.parseArray()