当前位置:网站首页>json.load(s)与json.dump(s)
json.load(s)与json.dump(s)
2022-06-10 15:23:00 【Hi~晴天大圣】
1、区别
json.load:表示读取json文件,返回python对象
json.dump:表示将json数据写入文件,文件为json字符串格式,无返回
json.loads:将json字符串转换为字典类型,返回python对象
json.dumps:将python中的字典类型转换为json字符串
load和dump处理的主要是文件
loads和dumps处理的是字符串
2、实践
2.1、json.dumps
import json
dict1 = {
"age": "12"}
json1 = json.dumps(dict1) # json.dumps()函数的使用,将字典转化为json字符串
print(json1)
运行的结果是:
{
"age": "12"}
2.2、json.loads
import json
json2 = '{"age": "12"}'
dict2 = json.loads(json2) # json.loads函数的使用,将字符串转化为字典
print(dict1)
运行的结果是:
{
'age': '12'}
2.3、json.dump
import json
json3 = "{'age': '12'}"
file = open(r'D:\Document\Workspace\pywokrspace\test1\001\1.json','w',encoding='utf-8')
json.dump(json3,file) # json.dump()函数的使用,将json信息写进文件
2.4、json.load
import json
file = open(r'D:\Document\Workspace\pywokrspace\test1\001\1.json','r',encoding='utf-8') # json.load()函数的使用,将读取json信息
json5 = json.load(file)
print(json5)
边栏推荐
- 农产品期货如何开户?有没有什么资金条件?
- Overview of cann interface calling process
- We media video Hot Ideas sharing
- Yuntu says that every successful business system cannot be separated from apig
- Hessian matrix of convex function and Gauss Newton descent method
- In what scenario can we not use the arrow function?
- Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
- Opentelemetry metrics release candidate
- Digital management medium + low code, jnpf opens a new engine for enterprise digital transformation
- Data Lake (VI): Hudi and Flink integration
猜你喜欢

数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎

One-way hash function

VINS理论与代码详解4——初始化

产品设计软件Figma用不了,国内有哪些相似功能的软件

ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解3——紧耦合优化模型

Common QR decomposition, SVD decomposition and other matrix decomposition methods of visual slam to solve full rank and deficient rank least squares problems (analysis and summary of the most complete

一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue

Development of stm8s103f single chip microcomputer (1) lighting of LED lamp

TensorFlow实战Google深度学习框架第二版学习总结-TensorFlow入门

AutoCAD - set text spacing and line spacing
随机推荐
VINS理論與代碼詳解4——初始化
Google Earth Engine(GEE)——基于s2影像的实时全球10米土地利用/土地覆盖(LULC)数据集
微信小程序 颜色渐变
企业如何提升文档管理水平
One-way hash function
音视频处理三剑客之 AEC:回声产生原因及回声消除原理
How to write a global notice component?
Cap version 6.1 Release Notice
Software intelligence: formal rules of AAAS system metrics and grammars
How does CRM help enterprises and salespeople?
We media video Hot Ideas sharing
【高代码文件格式API】上海道宁为您提供文件格式API集——Aspose,只需几行代码即可创建转换和操作100多种文件格式
cmake实战记录(一)
CAP 6.1 版本发布通告
ORB_ Slam2 visual inertial tight coupling positioning technology route and code explanation 0 - overall framework and theoretical basic knowledge
ORB_ Slam2 visual inertial tight coupling positioning technology route and code explanation 3 - tight coupling optimization model
Vins theory and code explanation 0 -- theoretical basis in vernacular
Jiabo gp2120tu label printer installation and use tutorial (PC)
AutoCAD - set text spacing and line spacing
OpenTelemetry Metrics发布候选版本