Javascript

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

 

这篇关于python json dumps() loads()的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!