我已经完成了我的应用程序,完成后会有两个 json 文件。我需要将它们组合在一个不同的java类中,所以我尝试过这样的事情
如果我尝试使用此代码
File dirSrc = new File(mydir);
File[] list = dirSrc.listFiles();
JSONArray jsonList = new JSONArray();
for (File file : list) {
try {
jsonList.put(new JSONObject(readFile(file)));
} catch (JSONException e) {
e.printStackTrace();
}
}
System.out.println(jsonList);
private String readFile(File file) {
String finalOutput = null;
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String str;
while ((str = in.readLine()) != null) {
finalOutput = str;
}
in.close();
} catch (IOException e) {
}
return finalOutput;
}
我得到一个 org.json.JSONException:Java.lang.String 类型的值 +k�V��䱐*ʜ� 无法转换为 JSONObject。有谁知道怎么回事?