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