JSON.simple
openkk
13年前
<p>JSON.simple是一个简单的Java类库,用于解析和生成JSON文本。不依赖于其它类库,性能高。</p> <ul> <li>Full compliance with <a href="/misc/goto?guid=4959499401825879130" rel="nofollow">JSON specification</a> (RFC4627) and reliable (see <a href="/misc/goto?guid=4959499401915947562">compliance testing</a>) </li> </ul> <ul> <li>Provides multiple functionalities such as encode, decode/parse and escape JSON text while keeping the library lightweight </li> </ul> <ul> <li>Flexible, simple and easy to use by reusing Map and List interfaces </li> </ul> <ul> <li>Supports streaming output of JSON text </li> </ul> <ul> <li>Stoppable SAX-like interface for streaming input of JSON text (learn <a href="/misc/goto?guid=4959499401986005624" rel="nofollow">more</a>) </li> </ul> <ul> <li>Heap based parser </li> </ul> <ul> <li>High performance (see <a href="/misc/goto?guid=4959499402072930935">performance testing</a>) </li> </ul> <ul> <li>No dependency on external libraries </li> </ul> <ul> <li>Both of the source code and the binary are JDK1.2 compatible </li> </ul> <p>示例代码:</p> <pre class="brush:java; toolbar: true; auto-links: false;">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);</pre> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1324198061530" target="_blank">http://www.open-open.com/lib/view/home/1324198061530</a></p> <p></p>