zoukankan      html  css  js  c++  java
  • 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")); }
  • 相关阅读:
    multidownloadXkcd 多线程抓图
    51job_selenium测试2
    51job_selenium测试
    python爬虫 前程无忧网页抓取
    化工pdf下载
    Velocity写法注意
    Velocity中文乱码问题解决方法
    velcoity使用说明:foreach指令
    strults2标签s:set的用法
    struts提交action乱码
  • 原文地址:https://www.cnblogs.com/chen-lhx/p/5150453.html
Copyright © 2011-2022 走看看