zoukankan      html  css  js  c++  java
  • 解析 Jason数据

    /**
    * <pre>
    * {
    * "id": 2,
    * "title": "json title",
    * "config": {
    * "width": 34,
    * "height": 35
    * },
    * "data": [
    * "JAVA",
    * "JavaScript",
    * "PHP"
    * ]
    * }
    * </pre>
    *
    * @param args
    */
    public static void main(String[] args)
    {
    System.out.println("----------------------------");
    String jsonStr = "{"id": 2," + " "title": "json title", " + ""config": {" + ""width": 34,"
    + ""height": 35," + "}, "data": [" + ""JAVA", "JavaScript", "PHP"" + "]}";
    System.out.println(jsonStr);
    System.out.println("----------------------------");
    JSONObject ob = JSONObject.parseObject(jsonStr);
    Set<String> obKeys = ob.keySet();

    for (String key : obKeys)
    {
    System.out.println(key + " : " + ob.getString(key));

    }
    System.out.println("----------------------------");
    // System.out.println(ob.values());

    JSONObject config = (JSONObject) ob.get("config");
    Set<String> configKeys = config.keySet();

    for (String key : configKeys)
    {
    System.out.println(key + " : " + config.getByteValue(key));

    }
    System.out.println("----------------------------");
    JSONArray array = (JSONArray) ob.get("data");
    ListIterator<Object> it = array.listIterator();
    while (it.hasNext())
    {
    System.out.println(it.next());
    }
    System.out.println("----------------------------");
    }

  • 相关阅读:
    c++ Knight Moves 超级升级版
    百度招聘彩蛋
    C++ 八数码问题宽搜
    c++ 动态规划(数塔)
    c++ 深度优先搜索(迷宫)
    c++ 宽搜(倒水)
    c++ matrix逆时针螺旋
    c++ 基数排序
    c++ 二分答案(解方程)
    c++ 二分答案(数组查找)
  • 原文地址:https://www.cnblogs.com/33blog/p/4138070.html
Copyright © 2011-2022 走看看