【发布时间】:2015-10-15 08:36:55
【问题描述】:
我正在我的 PC 上测试一个 servlet,但如果我运行它,我会在第 24 行得到 Unexpected Token end of File,即“Object obj = parser.parse(new FileReader("C:\libs\data.json "));"。
String id = request.getParameter("id");
JSONParser parser = new JSONParser();
FileWriter file;
file = new FileWriter("C:\\libs\\data.json");
try{
Object obj = parser.parse(new FileReader("C:\\libs\\data.json"));
JSONObject jsonObject = (JSONObject) obj;
String cont = (String) jsonObject.get(id);
System.out.println(cont);
int downloads = Integer.parseInt(cont);
++downloads;
jsonObject.put(id, downloads);
file.write(jsonObject.toJSONString());
}catch(Exception e){
e.printStackTrace();
}finally {
file.flush();
file.close();
}
【问题讨论】:
-
我怀疑 JSON 是无效的。不幸的是,我们看不到 JSON...