- JSON.simple Tutorial
- JSON.simple - Home
- JSON.simple - Overview
- JSON.simple - Environment Setup
- JSON.simple - JAVA Mapping
- Decoding Examples
- Escaping Special Characters
- JSON.simple - Using JSONValue
- JSON.simple - Exception Handling
- JSON.simple - Container Factory
- JSON.simple - Content Handler
- Encoding Examples
- JSON.simple - Encode JSONObject
- JSON.simple - Encode JSONArray
- Merging Examples
- JSON.simple - Merging Objects
- JSON.simple - Merging Arrays
- Combination Examples
- JSON.simple - Primitive, Object, Array
- JSON.simple - Primitive, Map, List
- Primitive, Object, Map, List
- Customization Examples
- JSON.simple - Customized Output
- Customized Output Streaming
- JSON.simple Useful Resources
- JSON.simple - Quick Guide
- JSON.simple - Useful Resources
- JSON.simple - Discussion
JSON.simple - Primitive, Map, List Combination
Using JSONValue object, we can create a JSON which comprises of primitives, Map and List.
Following example illustrates the above concept.
Example
import java.io.IOException; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.json.simple.JSONValue; class JsonDemo { public static void main(String[] args) throws IOException { Map m1 = new LinkedHashMap(); m1.put("k11","v11"); m1.put("k12","v12"); m1.put("k13", "v13"); List l1 = new LinkedList(); l1.add(m1); l1.add(new Integer(100)); String jsonString = JSONValue.toJSONString(l1); System.out.println(jsonString); } }
Output
[{"k11":"v11","k12":"v12","k13":"v13"},100]
Advertisements