我有一個(gè)管理數(shù)據(jù)的 Java 程序。當(dāng)它想從所述數(shù)據(jù)創(chuàng)建報(bào)告時(shí),它通過保存一個(gè)帶有報(bào)告相關(guān)數(shù)據(jù)的 JSON 文件,然后通過使用 ProcessBuilder 對象啟動(dòng) python 腳本來實(shí)現(xiàn)。但是,如果我嘗試從 python 腳本的輸出中提取數(shù)據(jù),我會(huì)遇到一個(gè)奇怪的錯(cuò)誤。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>"); */這工作正常并按預(yù)期生成報(bào)告(沒有輸入流代碼)。如果我然后取消注釋代碼,我會(huì)從 python 腳本中得到一個(gè)錯(cuò)誤。 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 進(jìn)程是如何導(dǎo)致錯(cuò)誤的,更重要的是如何修復(fù)它。下面是導(dǎo)致錯(cuò)誤的代碼(特別是最后一行:with open("InvoiceMakerDoc.json") as json_file: json_data=json_file.read() decoded_data =json.loads(json_data)
導(dǎo)致python腳本JSON錯(cuò)誤的Java進(jìn)程
慕標(biāo)琳琳
2021-07-23 16:01:14