java中JSONObject和JSONArray的区别:

1.JSONObject表示对象json:{"name":"tom"}

JSONObject jsonObject = new JSONObject(json);

2.JSONArray表示数组json:["tom","kate"]

JSONArray jsonArray = new JSONArray(json);

后端中想把一个json字符串(键值对形式)转化为对象的方法:

其中data是“键值对”形式的json字符串。

JSONObject jsonObject = JSON.parseObject(data);

如果想从刚刚获得的jsonObject对象中获取对象里面的数组:可以用JSONArray:

JSONArray jsonArray = jsonObject.getJSONArray("arrays");

如果刚刚获得的数组对象里面还包含的有很多对象,并且对象里还包含数组:如何获得里面的数组

for(int i = 0;i<jsonArray.size();i++){
JSONObject jsonObjest1 = jsonArray.getJSONObject(i)
JSONArray clomns = jsonObjest1.getJSONArray("key值")
}

参考博客:

(1)https://www.cnblogs.com/fu512/p/7595144.html

(2)https://blog.csdn.net/weixin_42204641/article/details/82850659

Guess you like

Origin blog.csdn.net/kkkkkfffd/article/details/121287340