Json Simple 简明教程
JSON.simple - Exception Handling
JSONParser.parse() 在 JSON 无效的情况下会引发 ParseException。以下示例演示了如何处理 ParseException。
Example
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
class JsonDemo {
public static void main(String[] args) {
JSONParser parser = new JSONParser();
String text = "[[null, 123.45, \"a\tb c\"]}, true";
try{
Object obj = parser.parse(text);
System.out.println(obj);
}catch(ParseException pe) {
System.out.println("position: " + pe.getPosition());
System.out.println(pe);
}
}
}