JSONObject和JSONArray遍历数组与对象
发布时间:2020-12-16 19:46:22 所属栏目:百科 来源:网络整理
导读:JSONObject和JSONArray的API链接: http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html http://json-lib.sourceforge.net/apidocs/net/sf/json/JSONArray.html 1、识别json格式字符串是JSONObject还是JSONArray JSON数据格式只有两
JSONObject和JSONArray的API链接:
http://json-lib.sourceforge.net/apidocs/jdk15/net/sf/json/JSONObject.html
http://json-lib.sourceforge.net/apidocs/net/sf/json/JSONArray.html
1、识别json格式字符串是JSONObject还是JSONArray JSON数据格式只有两种形式,分别是:
JSONObject可以用key取值,JSONArray只能遍历取值 2、遍历json数组 假设我们得到的json字符串result如下:
可以看出来,最外面是个json对象,photos节点是个数组,遍历代码如下:
|