- 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
- 属性示例
- org.json - 属性
- XML 示例
- org.json - XML
- 异常处理
- org.json - JSON异常处理
- org.json 有用资源
- org.json - 快速指南
- org.json - 有用的资源
- org.json - 讨论
Org.Json - JSON异常处理
如果 JSON 无效,org.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]