我一直收到一个错误解析JSON文件
输入
{“大陆”:“南美洲”、"recentJobRank":717、“纬度”:“-34.6037232”、"lastSeenDate":"2012-11-23“、"start":"Inmediato”、“contactPerson”、“Alejandra”、“lastJobRank”、“lastJobRank”、“标题”:“Encimador”、“工资”:“Convenio”、“jobtype”、“Tiempo”、"url":"http://www.computrabajo.com.ar/bt-ofrd-deglay-7148.htm","postedDate":"2012-11-21","duration":"Indeterminada","firstSeenDate":"2012-11-23","phoneNumber":"011 4648-0226 RRHH“、"faxNumber":"011 4648-0226”、“地点”:“布宜诺斯艾利斯”阿根廷“公司”:“Deglay S.R.L.”、"id":"34076“、”部门“:”布宜诺斯艾利斯“、”类别“:”其他“、”应用程序“:”Por-mail o comunicandose a los telefonos“、”经度“:”-58.3815931“}
以下是我收到的例外
异常
意外字符(J)在位置457。在org.json.simple.parser.Yylex.yylex(Yylex.java:610) at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)的加载项字段中捕获的异常
我试过在Validator.It上检查我的json似乎没问题。我犯了什么明显的错误?
发布于 2014-11-08 11:31:24
JSON绝对是正确的,因为JSON.parse()接受它。我不能用简单的json库来重现你的错误。我下载了所有可用的这里,复制粘贴了您的JSON字符串,并将其传递给了这里,并且在任何版本中都没有出现错误。
这是我的设置:
public static void main(String[] args) {
try {
StringReader x = new StringReader("{\"continent\":\"South America\",\"recentJobRank\":717,\"latitude\":\"-34.6037232\",\"lastSeenDate\":\"2012-11-23\",\"start\":\"Inmediato\",\"contactPerson\":\"Alejandra Perez\",\"lastJobRank\":2,\"title\":\"Encimador\",\"salary\":\"Convenio\",\"jobtype\":\"Tiempo Completo\",\"url\":\"http://www.computrabajo.com.ar/bt-ofrd-deglay-7148.htm\",\"postedDate\":\"2012-11-21\",\"duration\":\"Indeterminada\",\"firstSeenDate\":\"2012-11-23\",\"phoneNumber\":\"011 4648-0226 RRHH\",\"faxNumber\":\"011 4648-0226\",\"location\":\"Buenos Aires, Argentina\",\"company\":\"Deglay S.R.L.\",\"id\":\"34076\",\"department\":\"Buenos Aires\",\"category\":\"others\",\"applications\":\"Por e-mail o comunicandose a los telefonos\",\"longitude\":\"-58.3815931\"}");
new JSONParser().parse(x);
} catch(Exception e) {
System.out.println("Error: " + e);
}
System.out.println("Success");
}因此,我假设您的JSON和库都不是这里的错。我猜是JSON字符串的编码,因为错误消息显示
意外字符(J)在位置457。
在这个位置附近没有J。因此,您接收到的JSON要么是以一种SimpleJSON无法正确解析的方式编码的,要么是数据不能完全/正确地传输。
也许它可以帮助判断,从哪里获得JSON,以及如何将它传递到JSONParser.parse()。
https://stackoverflow.com/questions/26816260
复制相似问题