我是比較新的蟒蛇完全新的JSON文件,我試圖按照以下簡單的例子:錯誤打開JSON文件在Python
import json
# Load the data into a list
filename = 'population_data.json'
with open(filename) as f:
pop_data = json.load(f)
當我嘗試下載在這裏找到的數據:
https://github.com/ehmatthes/pcc/blob/master/chapter_16/population_data.json
我得到以下錯誤:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我在Windows 10中使用pycharm。 它可能與我從GitHub下載json文件的方式有關嗎?我將它作爲一個txt文件下載,然後將它保存爲一個Json文件,看起來是正確的,但顯然代碼無法正常工作。 如果這是不正確的,從Githib下載json文件的正確方法是什麼?
感謝
巴茲
從網頁加載它繞過了這個問題,請看這裏:https://stackoverflow.com/questions/12965203/how-to-get-json-from-webpage-into-python-script – Bazman
從webage加載它繞過這個問題,請看這裏:https://stackoverflow.com/questions/12965203/how-to-get-json-from-webpage-into-python-script。我仍然想知道如何正確保存文件,因此避免了對urllib的需求。 – Bazman