PythonVersion=3.9
json.version = '2.0.9'
我需要读取存储在本地的Json数据,使用"json.load()"函数,但是出错
if count < 1:
Hunger=100
money=100
sleep=0
life=100
experience=2
target=1
import json
dictObj = {
'Details':{
'Hunger': Hunger,
'money': money,
'sleep': sleep,
'life': life,
'experience': experience,
'target': target
}
}
else:
with open("details.json") as f:
json = open('details.json', 'w')
f = json.loads(json)
Hunger=f[Details]["Hunger"]
money=f[Details]["money"]
sleep=f[Details]["sleep"]
life=f[Details]["life"]
experience=f[Details]["experience"]
target=f[Details]["target"]
jsObj = json.dumps(dictObj)
fileObject = open('details.json', 'w')
fileObject.write(jsObj)
fileObject.close()
错误信息是:
Traceback (most recent call last):
File "Main.py", line 83, in <module>
f = json.loads(json)
AttributeError: '_io.TextIOWrapper' object has no attribute 'loads'
求解