- org.json 教程
- org.json - 主頁
- org.json - 概述
- org.json - 環境設定
- CSV 示例
- org.json - CDL
- Cookie 示例
- org.json - Cookie
- org.json - CookieList
- HTTP 標頭示例
- org.json - HTTP
- JSON 示例
- org.json - JSONArray
- org.json - JSONML
- org.json - JSONObject
- org.json - JSONStringer
- Property 示例
- org.json - Property
- XML 示例
- org.json - XML
- 異常處理
- org.json - JSONException 處理
- org.json 有用資源
- org.json - 快速指南
- org.json - 有用資源
- org.json - 討論
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());
}
}
}
輸出
<Other Details>null</Other Details> Misshaped close tag at 34 [character 35 line 1]
廣告