代碼:JSON Python的讀取/寫入到一個JSON文件問題
import json
numbers = [2, 3, 5, 7, 11, 13]
letters = ["a", "b", "c", "d"]
filename = 'numbers.json'
with open(filename, 'w') as f_obj:
json.dump(numbers, f_obj)
json.dump(letters, f_obj)
with open(filename) as f_obj:
numbers = json.load(f_obj)
letters = json.load(f_obj)
print(numbers)
print(letters)
我希望能夠讀取我已經加入到一個JSON文件多個列表,並將它們設置爲可以使用單獨的列表後來。
我不介意在json文件中的每個列表之間添加一個新行,然後以行格式讀取它。
你的問題是什麼? –