转自:https://blog.csdn.net/qq_30125555/article/details/79066036
JSON数据解析的有点在于他的体积小,在网络上传输的时候可以更省流量,所以使用越来越广泛,下面介绍使用JsonObject和JsonArray的两种方式解析Json数据。
使用以上两种方式解析json均需要依赖json-lib.jar开发包使用依赖包
1、JsonObject
使用JsonObject解析只有一条数据的json是非常方便的例如:”{\”name\”:\”zhangsan\”,\”password\”:\”zhangsan123\”,\”email\”:\”10371443@qq.com\”}”
public static void main(String[] args) {
String jsonString ="{\"name\":\"zhangsan\",\"password\":\"zhangsan123\",\"email\":\"10371443@qq.com\"}";
JSONObject json = JSONObject.fromObject(jsonString);
User user = new User()