json 序列化

 

 

Json反序列化如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
#coding: utf-8
import json
dict = {'name':'zhangsan', 'age':33, 'address':'红星路'}
print('未序列化前的数据类型为:', type(dict))
print('为序列化前的数据:', dict)
#对dict进行序列化的处理
dict_xu = json.dumps(dict,ensure_ascii=False#添加ensure_ascii=False进行序列化
print('序列化后的数据类型为:', type(dict_xu))
print('序列化后的数据为:', dict_xu)
#对dict_xu进行反序列化处理
dict_fan = json.loads(dict_xu)
print('反序列化后的数据类型为:', type(dict_fan))
print('反序列化后的数据为: ', dict_fan)


This entry was posted on 2018 年 07 月 05 日 and is filed under pplife. Written by: . You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.