我有这个有效载荷:
payload = {"data":{"horse_name": "beauty", "horse_id":"52", "is_manual":true }}
此返回:
> NameError: name 'true' is not defined
...这是正确的。
如何更改上述有效载荷以使其为True
,使其看起来像:
payload = {"data":{"horse_name": "beauty", "horse_id":"52", "is_manual":True }}
可能有更好的解决方案;
import json
from collections import namedtuple
data = {"data":{"horse_name": "beauty", "horse_id":"52", "is_manual":true }}
# Parse JSON into an object with attributes corresponding to dict keys.
x = json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
x.data.is_manual = True
print x
未测试。