
- org.json - Home
- org.json - Overview
- org.json - Environment Setup
- CSV Examples
- org.json - CDL
- Cookie Examples
- org.json - Cookie
- org.json - CookieList
- HTTP Header Examples
- org.json - HTTP
- JSON Examples
- org.json - JSONArray
- org.json - JSONML
- org.json - JSONObject
- org.json - JSONStringer
- Property Examples
- org.json - Property
- XML Examples
- org.json - XML
- Exception Handling
- org.json - JSONException Handling
- org.json Useful Resources
- org.json - Quick Guide
- org.json - Useful Resources
- org.json - Discussion
Org.Json - JSONException Handling
Utility classes of org.json throws JSONException in case of invalid JSON. Following example shows how to handle JSONException.
Example
import org.json.JSONException; import org.json.XML; public class JSONDemo { public static void main(String[] args) { try { //XML tag name should not have space. String xmlText = "<Other Details>null</Other Details>"; System.out.println(xmlText); //Convert an XML to JSONObject System.out.println(XML.toJSONObject(xmlText)); } catch(JSONException e){ System.out.println(e.getMessage()); } } }
Output
<Other Details>null</Other Details> Misshaped close tag at 34 [character 35 line 1]
Advertisements