json数据,字典和字符串相互转换

text = {"name":"Jack","age":29}
read_json = json.loads(text)      # 把字典转换为json
print(read_json)
print(type(read_json))

result = json.dumps(read_json)   # 把字典转为str
print(result )
print(type(result ))

结果

{'name': 'Jack', 'age': 29}
<class 'dict'>
{"name": "Jack", "age": 29}
<class 'str'>

猜你喜欢

转载自blog.csdn.net/luolinll1212/article/details/85851316
今日推荐