我只是想在Python中閱讀我的json文件。當我這樣做時,我在正確的文件夾中;我在下載中,我的文件被稱爲'Books_5.json'。然而,當我嘗試使用.read()函數,我得到的錯誤OSError:[Errno 22]當我嘗試.read()一個json文件
OSError: [Errno 22] Invalid argument
這是我的代碼:
import json
config = json.loads(open('Books_5.json').read())
這也引起了同樣的錯誤:
books = open('Books_5.json').read()
如果有幫助,這是我的數據看起來像一個小的片段:
{"reviewerID": "A10000012B7CGYKOMPQ4L", "asin": "000100039X", "reviewerName": "Adam", "helpful": [0, 0], "reviewText": "Spiritually and mentally inspiring! A book that allows you to question your morals and will help you discover who you really are!", "overall": 5.0, "summary": "Wonderful!", "unixReviewTime": 1355616000, "reviewTime": "12 16, 2012"}
{"reviewerID": "A2S166WSCFIFP5", "asin": "000100039X", "reviewerName": "[email protected] \"[email protected]\"", "helpful": [0, 2], "reviewText": "This is one my must have books. It is a masterpiece of spirituality. I'll be the first to admit, its literary quality isn't much. It is rather simplistically written, but the message behind it is so powerful that you have to read it. It will take you to enlightenment.", "overall": 5.0, "summary": "close to god", "unixReviewTime": 1071100800, "reviewTime": "12 11, 2003"}
我使用Python 3.6 MacOSX上
您是否嘗試過使用完整路徑?例如'開(R'C:\用戶\ your_name \下載\ Books_5.json')'?如果完整路徑有效,但相對路徑不適用,則當前工作目錄不在您認爲的位置。 – CoryKramer
哪個版本的Python?哪個OS? –
@DanilaGanchar讓我添加該信息感謝提醒 – user45254