JSON.simple

openkk 12年前發布 | 26K 次閱讀 JSON JSON開發包

JSON.simple是一個簡單的Java類庫,用于解析和生成JSON文本。不依賴于其它類庫,性能高。

  • Provides multiple functionalities such as encode, decode/parse and escape JSON text while keeping the library lightweight
  • Flexible, simple and easy to use by reusing Map and List interfaces
  • Supports streaming output of JSON text
  • Stoppable SAX-like interface for streaming input of JSON text (learn more)
  • Heap based parser
  • No dependency on external libraries
  • Both of the source code and the binary are JDK1.2 compatible

示例代碼:

System.out.println("=======decode=======");

  String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
  Object obj=JSONValue.parse(s);
  JSONArray array=(JSONArray)obj;
  System.out.println("======the 2nd element of array======");
  System.out.println(array.get(1));
  System.out.println();

  JSONObject obj2=(JSONObject)array.get(1);
  System.out.println("======field \"1\"==========");
  System.out.println(obj2.get("1"));   


  s="{}";
  obj=JSONValue.parse(s);
  System.out.println(obj);

  s="[5,]";
  obj=JSONValue.parse(s);
  System.out.println(obj);

  s="[5,,2]";
  obj=JSONValue.parse(s);
  System.out.println(obj);

項目主頁:http://www.baiduhome.net/lib/view/home/1324198061530

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!