我有一个管理数据的 Java 程序。当它想从所述数据创建报告时,它通过保存一个带有报告相关数据的 JSON 文件,然后通过使用 ProcessBuilder 对象启动 python 脚本来实现。但是,如果我尝试从 python 脚本的输出中提取数据,我会遇到一个奇怪的错误。
ProcessBuilder pythonProcess = new
ProcessBuilder("python","ReportingTool.py");
pythonProcess.directory(new File("invoice_python_files\\"));
Process pythonRunnable =pythonProcess.start();
/*
BufferedReader outputReader = new BufferedReader(new
InputStreamReader(pythonRunnable.getInputStream()));
BufferedReader errorReader = new BufferedReader(new
InputStreamReader(pythonRunnable.getErrorStream()));
String line =null;
System.out.println("<ERROR>");
while ( (line = errorReader.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
System.out.println("<Output">)
while ( (line = outputReader.readLine()) != null)
System.out.println(line);
System.out.println("</OUTPUT>");
*/
这工作正常并按预期生成报告(没有输入流代码)。如果我然后取消注释代码,我会从 python 脚本中得到一个错误。
File "C:\Users\o.cohen\AppData\Local\Programs\Python\Python36-
32\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我不明白 java 进程是如何导致错误的,更重要的是如何修复它。下面是导致错误的代码(特别是最后一行:
with open("InvoiceMakerDoc.json") as json_file:
json_data=json_file.read()
decoded_data =json.loads(json_data)
慕尼黑8549860
相关分类