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

  • 相关阅读:
    OC面向对象—封装
    OC内存管理
    OC方法和文件编译
    OC语言基础知识
    OC语言前期准备
    C语言指针基础
    C语言字符串
    C语言数组
    C语言内存分析
    C语言函数
  • 原文地址:https://www.cnblogs.com/33blog/p/4138070.html
Copyright © 2011-2022 走看看