当前第2页 返回上一页
2、json.dump()和json.load()主要用来读写json文件函数
二、测试
1 2 3 4 5 6 7 | import json
# json.dumps()函数的使用,将字典转化为字符串
dict1 = { "age" : "12" }
json_info = json.dumps(dict1)
print ( "dict1的类型:" +str(type(dict1)))
print ( "通过json.dumps()函数处理:" )
print ( "json_info的类型:" +str(type(json_info)))
|
1 2 3 4 5 6 7 8 | 1 import json
2
3 # json.loads函数的使用,将字符串转化为字典
4 json_info = '{"age": "12"}'
5 dict1 = json.loads(json_info)
6 print ( "json_info的类型:" +str(type(json_info)))
7 print ( "通过json.dumps()函数处理:" )
8 print ( "dict1的类型:" +str(type(dict1)))
|
1 2 3 4 5 6 | 1 import json
2
3 # json.dump()函数的使用,将json信息写进文件
4 json_info = "{'age': '12'}"
5 file = open( '1.json' , 'w' ,encoding= 'utf-8' )
6 json.dump(json_info,file)
|
1 2 3 4 5 6 | 1 import json
2
3 # json.load()函数的使用,将读取json信息
4 file = open( '1.json' , 'r' ,encoding= 'utf-8' )
5 info = json.load(file)
6 print (info)
|
以上就是认识python的json.dumps()和json.loads()的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中可变对象和不可变对象详解
Python中关于正则捕获操作的示例
学Python需要编程基础吗
Python如何读取sqlite数据库的文件?
Python是解释型语言吗
学Python能做什么的
Python数据怎么处理numpy.median
Python建立文件怎么弄
Python 矩阵增加一行或一列的实例_Python
Python使用cx_oracle模块操作oracle数据库详解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 认识python的json.dumps()和json.loads()