当前位置:网站首页>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 .
边栏推荐
- [MYCAT] Introduction to MYCAT
- Target detection tagged data enhancement code
- YOLOv5学习总结(持续更新)
- GCC 中__attribute__((constructor)和__attribute__(((destructor))的注意事项。
- Likeshop100% open source encryption free B2B2C multi merchant mall system
- Signals and systems: Hilbert transform
- STM32 DSP库MDK VC5\VC6编译错误: 256, (const float64_t *)twiddleCoefF64_256, armBitRevIndexTableF64_256,
- Two architectures of data integration: ELT and ETL
- [activiti] gateway
- 测试数据增强后标签和数据集是否对应
猜你喜欢

What do programmers often mean by API? What are the API types?

STM32 DSP库MDK VC5\VC6编译错误: 256, (const float64_t *)twiddleCoefF64_256, armBitRevIndexTableF64_256,

数组常用方法

Jupyter notebook选择conda环境
![[MYCAT] MYCAT sub database and sub table](/img/a8/ebaedfa084754ef3c96f42ed78eb81.png)
[MYCAT] MYCAT sub database and sub table
![[MYCAT] MYCAT configuration file](/img/53/63a633d3ae917e3754f9f7f5c6567f.png)
[MYCAT] MYCAT configuration file

Chapter III summary of linear model

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

学习率余弦退火衰减之后的loss

AD1256
随机推荐
学习率余弦退火衰减之后的loss
jestson安装ibus输入法
Numpy cheatsheet
Qt 使用纯代码画图异常
在网络中添加SE通道注意力模块
【树莓派4B】七、远程登录树莓派的方法总结XShell,PuTTY,vncServer,Xrdp
Typora 安装包2021年11月最后一次免费版本的安装包下载V13.6.1
Delete the weight of the head part of the classification network pre training weight and modify the weight name
"Statistical learning methods (2nd Edition)" Li Hang Chapter 17 latent semantic analysis LSA LSI mind mapping notes and after-school exercise answers (detailed steps) Chapter 17
DeepSort 总结
es6常用特性
[activiti] activiti process engine configuration class
Native JS magnifying glass effect
[activiti] activiti environment configuration
解决ModularNotFoundError: No module named “cv2.aruco“
Common methods of array
《统计学习方法(第2版)》李航 第22章 无监督学习方法总结 思维导图笔记
Add se channel attention module to the network
字符串方法以及实例
Openwrt quick configuration Samba