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 - Exception Handling
JSON.simple - Exception Handpng
JSONParser.parse() throws ParseException in case of invapd JSON. Following example shows how to handle ParseException.
Example
import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; class JsonDemo { pubpc static void main(String[] args) { JSONParser parser = new JSONParser(); String text = "[[null, 123.45, "a b c"]}, true"; try{ Object obj = parser.parse(text); System.out.println(obj); }catch(ParseException pe) { System.out.println("position: " + pe.getPosition()); System.out.println(pe); } } }
Output
position: 24 Unexpected token RIGHT BRACE(}) at position 24.Advertisements