java获取json数组格式中的值

第一种方法:

 String str = "{'array':[{'id':5,'name':'张三'},{'id':6,'name':'李四'}]}";
 JSONArray jsonArray = null;
 jsonArray = jsonobj.getJSONArray("array");//获取数组
 System.out.println(jsonArray.getJSONObject(0).get("name"));

String str = "[{'columnId':5,'columnName':'人文历史'},{'columnId':2,'columnName':'商业视野'}]}";
JSONArray jsonArray = null;
jsonArray = new JSONArray(str);
System.out.println(jsonArray.getJSONObject(0).get("columnName"));

第二种方法:

 JSONObject json1=JSONObject.fromObject("{'username' : '11111','clientid' : '','password' : '222222'}");  
Map<String, Object> map =json1;  
for (Entry<String, Object> entry : map.entrySet()) {  
     System.out.println(entry.getKey()+"="+entry.getValue());  
 }  

原帖:https://www.cnblogs.com/kkxwze/p/11134846.html

原文地址:https://www.cnblogs.com/sjzxs/p/11984058.html