当前位置:网站首页>json. Load (s) and json dump(s)
json. Load (s) and json dump(s)
2022-06-10 15:32:00 【Hi~ sunny day Saint】
1、 difference
json.load: Means read json file , return python object
json.dump: It means that you will json Write data to file , File for json String format , No return
json.loads: take json Convert string to dictionary type , return python object
json.dumps: take python The dictionary type in is converted to json character string
load and dump It mainly deals with files
loads and dumps It deals with strings
2、 practice
2.1、json.dumps
import json
dict1 = {
"age": "12"}
json1 = json.dumps(dict1) # json.dumps() Use of functions , Translate the dictionary into json character string
print(json1)
The result of the operation is :
{
"age": "12"}
2.2、json.loads
import json
json2 = '{"age": "12"}'
dict2 = json.loads(json2) # json.loads Use of functions , Convert strings to dictionaries
print(dict1)
The result of the operation is :
{
'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() Use of functions , take json Write information into the file
2.4、json.load
import json
file = open(r'D:\Document\Workspace\pywokrspace\test1\001\1.json','r',encoding='utf-8') # json.load() Use of functions , Will read json Information
json5 = json.load(file)
print(json5)
边栏推荐
- CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement
- Ada Logics:CRI-O整体安全审计项目
- Applet network request promise
- Summary of methods for point projection onto a plane
- How to improve document management
- 虚拟机ping不通的几种原因及解决办法
- After class assignment for module 8 of phase 6 of the construction practice camp
- ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解2——IMU初始化
- Problems with database creation triggers
- uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题
猜你喜欢

CentOS Linux is dead! Oracle Linux may be a better alternative

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

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

4. Meet panuon again UI. Title bar of silver form

Several reasons and solutions of virtual machine Ping failure

CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement

ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解1——IMU流型预积分

音视频处理三剑客之 AEC:回声产生原因及回声消除原理

Information theory and coding 2 final review BCH code

uniapp中常用到的方法(部分) - 時間戳問題及富文本解析圖片問題
随机推荐
ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解3——紧耦合优化模型
智能电网终极Buff | 广和通模组贯穿“发、输、变、配、用”全环节
Get to know RPC
从“初代播种”到“落地生花”,广和通在5G商用三年间做了什么?
自推荐-深入理解RUST标准库内核
详解OpenCV的函数filter2D(),并提醒大家它做的运算并不是卷积运算而是相关运算
Kubernetes 1.24:statefulset introduces maxunavailable copies
Odoo authority management (access authority and record rules) is applied to upgrade role management
How to write a global notice component?
How to build a customer-centric product blueprint: suggestions from the chief technology officer
港大、英伟达 | Factuality Enhanced Language Models for Open-Ended Text Generation(用于开放式文本生成的事实性增强语言模型)
How the autorunner automated test tool creates a project -alltesting | Zezhong cloud test
广和通高算力智能模组为万亿级市场5G C-V2X注智
Baidu open source ice-ba installation and operation summary
Google Earth engine (GEE) - real time global 10 meter land use / land cover (LULC) data set based on S2 images
百度开源ICE-BA安装运行总结
Huawei cloud SRE deterministic O & M introduction
QT 基于QScrollArea的界面嵌套移动
Golang beep package playback MP3 cannot get the total length streamer Len() is 0, but other formats can
QT interface nested movement based on qscrollarea