序列化:把python数据类型转化成str的类型的过程(dict—>str)
反序列化:把str类型转化成python数据类型的数据结构(str—>dict)
dict1 = {
"code": "1",
"msg": "供货厂商列表",
"data":
{
"stores_id": 1,
"stores_name": "厂商用户1"
}
}
dict_str = json.dumps(dict1)
print(dict_str, type(dict_str))
{
"code": "1", "msg": "\u4f9b\u8d27\u5382\u5546\u5217\u8868", "data": {
"stores_id": 1, "stores_name": "\u5382\u5546\u7528\u62371"}} <class 'str'>
str_dict = json.loads(dict_str)
print(str_dict, type(str_dict))
{
'code': '1', 'msg': '供货厂商列表', 'data': {
'stores_id': 1, 'stores_name': '厂商用户1'}} <class 'dict'>