当前位置:网站首页>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)
边栏推荐
- Wechat applet color gradient
- Cmake actual combat record (I)
- 无线通信模组如何助力智能无人机打造“空中物联网”?
- ORB_ Slam2 visual inertial tight coupling positioning technology route and code explanation 2 - IMU initialization
- Tensorflow actual combat Google deep learning framework second edition learning summary tensorflow introduction
- Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
- RSA a little bit of thought
- cmake实战记录(一)
- QT 基于QScrollArea的界面嵌套移动
- CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement
猜你喜欢

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

In what scenario can we not use the arrow function?

uniapp中常用到的方法(部分) - 時間戳問題及富文本解析圖片問題

Problems with database creation triggers

How the autorunner automated test tool creates a project -alltesting | Zezhong cloud test

uniapp中常用到的方法(部分) - 时间戳问题及富文本解析图片问题

This article introduces you to j.u.c's futuretask, fork/join framework and BlockingQueue

Beginner pytorch step pit

Yuntu says that every successful business system cannot be separated from apig

影刀RPA学习和遇见excel部分问题解决方式
随机推荐
Summary of methods for point projection onto a plane
Summary of 5 years' experience in ERP odoo privilege management system setup
自媒体视频热门思路分享
How to build a customer-centric product blueprint: suggestions from the chief technology officer
Comment construire un plan de produit axé sur le client: conseils du CTO
cmake实战记录(一)
从“初代播种”到“落地生花”,广和通在5G商用三年间做了什么?
Golang beep package playback MP3 cannot get the total length streamer Len() is 0, but other formats can
Kubernetes 1.24: 防止未经授权的卷模式转换
terminator如何设置字体显示不同颜色
在什么场景下,我们不能使用箭头函数?
ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解3——紧耦合优化模型
rk3399_9.0去掉设置的一级菜单network & internet
HKU and NVIDIA | factuality enhanced language models for open ended text generation
RSA a little bit of thought
After class assignment for module 8 of phase 6 of the construction practice camp
Hutool Usage Summary (VIP collection version)
CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement
Cmake actual combat record (I)
Google Earth engine (GEE) - real time global 10 meter land use / land cover (LULC) data set based on S2 images