我收到错误代码(下面),我无法解码字符串,我知道它是找到JSON和我保存的文件,但它没有解析。 错误代码:
Unexpected token VALUE(-10) at position 83.
at org.json.simple.parser.JSONParser.parse(JSONParser.java:257)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:81)
at org.json.simple.parser.JSONParser.parse(JSONParser.java:75)
at Employee.retrieveData(Employee.java:103)
at EmployeeTest.main(EmployeeTest.java:9)
代码:
JSONParser parser = new JSONParser();
String s = null;
try {
if (!file.exists()) {
System.out.println("Error: No Data");
return;
}
FileReader fr = new FileReader(file.getAbsoluteFile());
BufferedReader br = new BufferedReader(fr);
s=br.readLine();
fr.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
//s = {"firstName":"Bob","lastName":"Hope","isEmployeeClockedIn":false,"clockedOut":2015-10-06 23:51:10.751,"id":0,"clockedIn":2015-10-06 23:51:10.751}
Object obj = parser.parse(s);
JSONArray array = (JSONArray)obj;
System.out.println(obj);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
答案 0 :(得分:0)
这是无效的JSON:
{"firstName":"Bob","lastName":"Hope","isEmployeeClockedIn":false,"clockedOut":2015-10-06 23:51:10.751,"id":0,"clockedIn":2015-10-06 23:51:10.751}
该解析失败了" clockedOut":2015 -10 -06。
应该引用该值:
"clockedOut":"2015-10-06 23:51:10.751"