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("----------------------------");
    }

  • 相关阅读:
    [bzoj1568]李超线段树模板题(标志永久化)
    [tyvj1860]后缀数组
    [poj3264]rmq算法学习(ST表)
    LintCode-82.落单的数
    LintCode-53.翻转字符串
    LintCode-56.两数之和
    LintCode-379.将数组重新排序以构造最小值
    LintCode-5.第k大元素
    LintCode-3.统计数字
    LintCode-4.丑数 II
  • 原文地址:https://www.cnblogs.com/33blog/p/4138070.html
Copyright © 2011-2022 走看看