python json dumps() loads()

时间:2021-07-22 17:38:51   收藏:0   阅读:0

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‘}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!