- 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]
广告