编程语言
首页 > 编程语言> > python json dumps() loads()

python json dumps() loads()

作者:互联网

dumps() 转换成json

loads() 转换成dict

import json

dict = {'a': 'wo', 'b': 'zai', 'c': 'zhe', 'd': 'li'}
string = json.dumps(dict)
loads = json.loads(string)

print("type(string):", type(string))
print("type(loads):", type(loads))

print("string:", string)
print("loads:", loads)
type(string): <class 'str'>
type(loads): <class 'dict'>
string: {"a": "wo", "b": "zai", "c": "zhe", "d": "li"}
loads: {'a': 'wo', 'b': 'zai', 'c': 'zhe', 'd': 'li'}

 

标签:string,zai,python,dumps,json,print,loads,type
来源: https://www.cnblogs.com/luckygxf/p/15042256.html