JSON.simple
JSON.simple是一個簡單的Java類庫,用于解析和生成JSON文本。不依賴于其它類庫,性能高。
- Full compliance with JSON specification (RFC4627) and reliable (see compliance testing)
- 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
- High performance (see performance testing)
- 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);
本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!