一://json数组类型字符串取值 var jsonStr = ‘[{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"01","open":false,"pId":"0","name":"A部门"},{"id":"011","open":false,"pId":"01","name":"A部门"},{"id":"03","open":false,"pId":"0","name":"A部门"},{"id":"04","open":false,"pId":"0","name":"A部门"}, {"id":"05","open":false,"pId":"0","name":"A部门"}, {"id":"06","open":false,"pId":"0","name":"A部门"}]‘; var jsonObj = JSON.parse(jsonStr);//转换为json对象 for(var i=0;i<jsonObj.length;i++){ alert(jsonObj[i].id); //取json中的值 } console.log(jsonObj) var jsonStr1 = JSON.stringify(jsonObj) console.log(jsonStr1+"jsonStr1")
二:
public static void main(String[] args) throws Exception {
List list=new ArrayList<>() ;
ArrayList<Object> alist=new ArrayList<>();
Map<Object, List> map=new HashMap<Object, List>();
list.add("ss");
list.add("dd");
alist.add("hh");
alist.add("yy");
map.put("a", list);
map.put("b", alist);
String ss=JSON.toJSONString(map);
JSONObject jsonObject=JSON.parseObject(ss);
String hhString=jsonObject.getString("a");
JSONArray ssssArray=(JSONArray) JSONArray.parse(hhString);
System.out.println(ssssArray.get(0));
}
三:
Map mapsMap=new HashMap<>();
mapsMap.put("1", 2);
mapsMap.put("2", 3);
Map<Object, Map> map=new HashMap<Object, Map>();
map.put("a", mapsMap);
map.put("b", mapsMap);
String ss=JSON.toJSONString(map);
System.out.println(ss);
String hhString=jsonObject.getString("a");
System.out.println(hhString);
}
原文地址:https://www.cnblogs.com/cws-kf/p/8630615.html