org.json - JSONException हैंडलिंग

Org.json की उपयोगिता कक्षाएं अमान्य JSON के मामले में JSONException को फेंकती हैं। निम्नलिखित उदाहरण से पता चलता है कि JSONException को कैसे संभालना है।

उदाहरण

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());
      }
   }
}

उत्पादन

position: 24
Unexpected token RIGHT BRACE(}) at position 24.