java 解析 json 遍歷未知key


1、——————————————————————————————————————————————————————————————
import net.sf.json.JSONObject; String json = "{\"name\":\"lss\"}"; JSONObject jsonObj = JSONObject.fromObject(json); String name = jsonObj.getString("name"); Iterator it = jsonObj.keys(); List<String> keyListstr = new ArrayList<String>(); while(it.hasNext()){ key = (String) it.next();
     value = jsonObject.getString(key);
}

 

2、 {"info":[{"goodsId":"1234","goodsq":"10"},{"goodsId":"5678","goodsq":"20"}]}

2、———————————————————————————————————————————————————————————————
JSONObject jsonObject
= new JSONObject(jsonString);   JSONArray jsonArray =jsonObject.getJSONArray(“info”);   for (int i = 0; i < jsonArray.length(); i++) {   JSONObject jo = jsonArray.getJSONObject(i);        System.out.println(jo.getString("goodsld"));        System.out.println(jo.getString("goodsq")); }

 


免責聲明!

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



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