Monday, 13 May 2013

JSON.simple Example

JSON.simple Example


JSON simple is a simple Java toolkit for JSON . You can use JSON simple to encode or
decode JSON text.
Features :
1 : Full compliance with JSON specification (RFC4627) and reliable.
2 : Provides multiple functionalities such as encode, decode/parse and escape
JSON text while keeping the library lightweight.
3 : Flexible, simple and easy to use by reusing Map and List interfaces.
4 : Supports streaming output of JSON text.
5 : Heap based parser.
6 : High performance.
7 : No dependency at all.

You need to download the JSON.simple library here and include it in java classpath.
1 : Write JSON to File
Write JSON data via JSONObject and JSONArray, and save it into a file named test.json


2 : Read JSON from File
Use JSONParser to read above generated JSON file test.json, and display each of the values.

Encode a JSON object - Streaming

Encode a JSON object - Using Map

Encode a JSON object - Using Map and streaming

No comments:

Post a Comment