python中json字符串转object import json
from collections import namedtuple
if __name__ == '__main__':
data = '{"name":"John Smith","hometown": {"name":"New York","id": 123}}'
# 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()))
print(x.name, x.hometown.name, x.hometown.id)python json字符串转数组
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论