我正在尝试解析以下json。这必须给我一个错误,说不正确的 json 格式。但是解析器只解析 json 直到 "value:15" 并且没有抛出任何异常。我怎样才能做到这一点?
String json = { and : [{key: domain, value: cricket}, {key : STAT_CDE,value : 15}]}, { and : [{key: domain, value: football}, {key : STAT_CDE,value : 10}]}
我正在使用的示例代码:
import org.codehaus.jackson.map.ObjectMapper;
ObjectMapper mapper = new ObjectMapper();
mapper.readTree(json); //this line is not throwing me any exception
这是代码片段:
import org.codehaus.jackson.map.ObjectMapper;
public class JsonTestParse {
public static void main(String[] args) {
String json = "{ \"and\" : [{\"key\": \"domain\", \"op\": \"=\", \"value\": \"cricket\"}, {\"key\" : \"STAT_CDE\",\"op\" : \"=\",\"value\" : \"13\"}]},"+
"{ \"and\" : [{\"key\": \"domain\", \"op\": \"=\", \"value\": \"Football\"}, {\"key\" : \"STAT_CDE\",\"op\" : \"=\",\"value\" : \"10\"}]}";
System.out.println("json: " + json);
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readTree(json);
} catch (Exception e) {
System.out.println("object mapper exp");
}
System.out.println("mapper complete");
}
}
和输出:
第 1 行: json: { "and" : [{"key": "domain", "op": "=", "value": "cricket"}, {"key" : "STAT_CDE","op" : "=","value" : "13"}]},{ "and" : [{"key": "domain", "op": "=", "value": "Football"}, {"key " : "STAT_CDE","op" : "=","value" : "10"}]} 第 2 行:映射器完成