python json 的loads() 格式?
import json
a = '{"aaa": "xxx", "bbb": True, "ccc": 0, "ddd":null}'
b = '{aaa: xxx, bbb: True, ccc: 0, ddd:null}'
e = "{aaa: xxx, bbb: True, ccc: 0, ddd:null}"
f = "{'aaa': 'xxx', 'bbb': True, 'ccc': 0, 'ddd':null}"
g = "{'aaa': 'xxx', 'bbb': True, 'ccc': 0, 'ddd':null}"
c = json.loads(f) # ←這裡括號裝abefg都無效,都會出錯
print("loads = ", f) ## 我goo了一下,有的說是必用雙引號包,loads()對格式很要求,但如上面所示,各種組合都會出錯,一開頭就錯了,後面沒辦法做。懇請大大指導一下。
d = json.dumps(b) # ←這個dumps是沒問題的
print("dumps = ", d)
請試著把 True
改成 true
應該就可以了
import json
a = '{"aaa": "xxx", "bbb": true, "ccc": 0, "ddd": null}'
c = json.loads(a)
print("loads = ", c)
# loads = {'aaa': 'xxx', 'bbb': True, 'ccc': 0, 'ddd': None}
https://docs.python.org/3/library/json.html#encoders-and-decoders