当前位置:网站首页>JSON. Dumps() function parsing
JSON. Dumps() function parsing
2022-07-24 05:57:00 【Didi'cv】
json.dumps()
json.dumps Will a Python The data structure is converted to JSON
import json
data = {
'name' : 'myname',
'age' : 100,
}
json_str = json.dumps(data)
json Some usage of Library
| Method | effect |
|---|---|
| json.dumps() | take python The object is encoded as Json character string |
| json.loads() | take Json The string is decoded into python object |
| json.dump() | take python Convert objects in to json Save to file |
| json.load() | In the file json In the form of python Object extraction |
json.dump() and json.dumps() The difference between
json.dumps() It's a python Object conversion to json A process of objects , The result is a string .
json.dump() It's a python Object conversion to json Object generates a fp File stream for , Related to documents .
json Parameters
json.dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding="utf-8", default=None, sort_keys=False, **kw)
- obj: Turn it into json The object of .
- sort_keys =True: Is to tell the encoder to sort according to the dictionary (a To z) Output . If it's a dictionary type python object , Just sort the keywords according to the dictionary .
- indent: Parameters are indented according to the data format , Read more clearly .
- separators: It's a separator , The meaning of the parameter is different dict Separator between items and dict Intra item key and value Separator between , hold : and , The following spaces have been removed .
import json
x = {
'name':' Have a guess ','age':19,'city':' sichuan '}
# use dumps take python Code as json character string
y = json.dumps(x)
print(y)
i = json.dumps(x,separators=(',',':'))
print(i)
# Output results
{
"name": "\u4f60\u731c", "age": 19, "city": "\u56db\u5ddd"}
{
"name":"\u4f60\u731c","age":19,"city":"\u56db\u5ddd"}
- skipkeys: The default value is False, If dict Of keys The data in is not python Basic type (str,unicode,int,long,float,bool,None), Set to False when , Will report TypeError Error of . This is set to True, You will skip this kind of key .
- ensure_ascii=True: Default output ASCLL code , If this should be False, You can output Chinese .
- check_circular: If check_circular by false, Then skip the circular reference check on the container type , Circular references will cause overflow errors ( Or worse ).
- allow_nan: If allow_nan For false , be ValueError Floating point values out of range will be serialized (nan、inf、-inf), Strictly observe JSON standard , Instead of using JavaScript Equal value (nan、Infinity、-Infinity).
- default:default(obj) It's a function , It should return a serializable obj Version or type error . Default values only cause type errors .
边栏推荐
- [activiti] activiti process engine configuration class
- Inventory of well-known source code mall systems at home and abroad
- 《统计学习方法(第2版)》李航 第22章 无监督学习方法总结 思维导图笔记
- [MYCAT] MYCAT configuration file
- Problems in SSM project configuration, various dependencies, etc. (for personal use)
- 《统计学习方法(第2版)》李航 第17章 潜在语义分析 LSA LSI 思维导图笔记 及 课后习题答案(步骤详细)第十七章
- 【深度学习】手把手教你写“手写数字识别神经网络“,不使用任何框架,纯Numpy
- 信号与系统:希尔伯特变换
- Could not load library cudnn_ cnn_ infer64_ 8.dll. Error code 126Please make sure cudnn_ cnn_ infer64_ eight
- In GCC__ attribute__ ((constructor) and__ attribute__ ((destructor)).
猜你喜欢

【深度学习】手写神经网络模型保存
![[activiti] Introduction to activiti](/img/99/e973279d661960853b3af69a7e8ef2.png)
[activiti] Introduction to activiti

《机器学习》(周志华)第2章 模型选择与评估 笔记 学习心得

Machine learning (zhouzhihua) Chapter 2 model selection and evaluation notes learning experience

列表写入txt直接去除中间的逗号

如何解决训练集和测试集的分布差距过大问题

《信号与系统》(吴京)部分课后习题答案与解析

Common features of ES6

西瓜书/南瓜书--第1,2章总结

"Statistical learning methods (2nd Edition)" Li Hang Chapter 16 principal component analysis PCA mind map notes and after-school exercise answers (detailed steps) PCA matrix singular value Chapter 16
随机推荐
GCC 中__attribute__((constructor)和__attribute__(((destructor))的注意事项。
删除分类网络预训练权重的的head部分的权重以及修改权重名称
PyTorch 单机多卡分布式训练
[activiti] gateway
vscode 多行注释总是会自动展开的问题
【深度学习】手写神经网络模型保存
[activiti] Introduction to activiti
YOLOv5学习总结(持续更新)
Xshell远程访问工具
STM32 standard peripheral Library (Standard Library) official website download method, with 2021 latest standard firmware library download link
[activiti] activiti process engine configuration class
信号与系统:希尔伯特变换
jupyter notebook一直自动重启(The kernel appears to have died. It will restart automatically.)
谷歌/火狐浏览器管理后台新增账号时用户名密码自动填入的问题
Openwrt quick configuration Samba
Multi merchant mall system function disassembly lecture 13 - platform side member management
systemctl + journalctl
Problems in SSM project configuration, various dependencies, etc. (for personal use)
[deep learning] teach you to write "handwritten digit recognition neural network" hand in hand, without using any framework, pure numpy
[activiti] process variables