1 import json
2 dict= {1:2, 3:4, "55":"66"}
3 print type(dict), dict
4
5 # test json.dumps
6 json_str = json.dumps(dict)
7 print type(json_str), json_str
8
9 # test json.loads
10 dict_2 = json.loads(json_str)
11 print type(dict_2), dict_2
1 #输出如下
2 <type ‘dict‘> {‘55‘: ‘66‘, 1: 2, 3: 4}
3 <type ‘str‘> {"55": "66", "1": 2, "3": 4}
4 <type ‘dict‘> {u‘55‘: u‘66‘, u‘1‘: 2, u‘3‘: 4}
总结:
json.dumps : dict转成str
json.loads:str转成dict
如此简单。不懂的可以拿把刀问候我。。
json.dumps : dict转成str json.loads:str转成dict
原文:https://www.cnblogs.com/jessitommy/p/11076366.html
