Python json.dumps & json.loads
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12199828.html
json.dumps
# dict => json str data_dict = { 'username' : 'hello', 'password' : 'world' } result_str = json.dumps(data_dict) type(result_str)
json.loads
# json str => dict data_str = '{"username": "hello", "password": "world"}' result_dict = json.loads(data_str) type(result_dict)
Console Output
Note
dumps_data = json.dumps(result, indent=4, ensure_ascii=False)
如若需要输出格式良好的并且允许中文编码,需要额外设置indent和ensure_ascii两个参数
Reference
强者自救 圣者渡人