JSON.simple Tutorial
Selected Reading
- JSON.simple - Discussion
- JSON.simple - Useful Resources
- JSON.simple - Quick Guide
- Customized Output Streaming
- JSON.simple - Customized Output
- Primitive, Object, Map, List
- JSON.simple - Primitive, Map, List
- JSON.simple - Primitive, Object, Array
- JSON.simple - Merging Arrays
- JSON.simple - Merging Objects
- JSON.simple - Encode JSONArray
- JSON.simple - Encode JSONObject
- JSON.simple - Content Handler
- JSON.simple - Container Factory
- JSON.simple - Exception Handling
- JSON.simple - Using JSONValue
- Escaping Special Characters
- JSON.simple - JAVA Mapping
- JSON.simple - Environment Setup
- JSON.simple - Overview
- JSON.simple - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JSON.simple - Primitive, Object, Array
JSON.simple - Primitive, Object, Array
Using JSONArray object, we can create a JSON which comprises of primitives, object and array.
Following example illustrates the above concept.
Example
import java.io.IOException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; class JsonDemo { pubpc static void main(String[] args) throws IOException { JSONArray pst1 = new JSONArray(); pst1.add("foo"); pst1.add(new Integer(100)); JSONArray pst2 = new JSONArray(); pst2.add(new Double(1000.21)); pst2.add(new Boolean(true)); pst2.add(null); JSONObject obj = new JSONObject(); obj.put("name", "foo"); obj.put("num", new Integer(100)); obj.put("balance", new Double(1000.21)); obj.put("is_vip", new Boolean(true)); obj.put("pst1", pst1); obj.put("pst2", pst2); System.out.println(obj); } }
Output
{"pst1":["foo",100],"balance":1000.21,"is_vip":true,"num":100,"pst2":[1000.21,true,null],"name":"foo"}Advertisements