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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM