我尝试在我的应用中使用JSON。在IDEA中可以正常运行,但是如果我创建jar文件,则行:
新的JSONObject(行)
不创建JSONObject。我敢肯定,如果在此行之后我什么都没用,请在jar中使用sout进行lil调试。
在旧版本中,我使用了 org.json 20180813 ,它正在工作,但现在我不知道为什么不这样做。
有人可以提供一些解决方案或建议吗?此行上的程序只是停止并且什么也不做,但是不会因任何错误而关闭。
private void getItems() {
long searchingTimeOut = Clock.systemDefaultZone().millis() + 8000;
if (Files.exists(MyJsonObj)) {
while (true) {
try {
byte[] byteLine = Files.readAllBytes(MyJsonObj);
String line = new String(byteLine, StandardCharsets.UTF_8);
if (line.endsWith("}}")) {
setItems(new JSONObject(line));
break;
}
if (searchingTimeOut < Clock.systemDefaultZone().millis()) {
setEmptyJson();
break;
}
} catch (IOException e) {
setEmptyJson();
delFiles();
break;
}
}
} else {
setEmptyJson();
}
delFiles();
}
答案 0 :(得分:0)
已解决!
文件>项目结构>工件
在“ 可用元素”中选择“ Maven:org.json:json ”并设置“ 提取到输出根目录”