当前位置:网站首页>序列化、编码、requests库json和data参数
序列化、编码、requests库json和data参数
2022-08-10 05:35:00 【蓝尼亚】
以下是疑惑了我很久的2个问题,终于得到答案,开心,如果阐述不对,欢迎各位大佬指正~
1.序列化、编码理解
(1)序列化
python对象——>字节(计算机可理解和存储、传输的形式)
eg:python对象(字典)——>json串(字节保存,字符串展示)
json.dumps(dict_type)
反序列
字节——>python对象
eg:json串(字节保存,字符串展示)——>python对象(字典)
json.loads(json串)
(2)编码与解码
编码:人类语言转换为机器语言,反之为解码
编码和解码过程如下:
应用
编码解码:解决展示问题(机器语言和人类语言的矛盾)
通俗点:计算机根据编码表,解码、编码
序列化:解决存储、传输的问题
2.requests库中的json和data参数
定义了content-type,需要结合content-type分析
content-type:json/application,需要传输json串
json参数:会自动将对象转成json串:需要传入字典
data参数:传入json字符串
content-type:application/x-www-form-urlencoded,需要form表单,传输键值对
data参数:字典
如果没有定义content-type类型,会根据 json参数/data参数传入的类型,决定content-type类型
参考
边栏推荐
猜你喜欢
随机推荐
pytorch-07.处理多维特征的输入
STM32F407ZG 看门狗 IWDG & WWDG
LeetCode 292. Nim Game (Simple)
Pytorch - 07. Multidimensional characteristics of input processing
el-dropdown drop-down menu style modification, remove the small triangle
二维卷积定理的验证(上)
51单片机教室人数进出统计检测数码管显示装置红外传感器
C陷阱与缺陷 个人阅读笔记
pytorch-11.卷积神经网络(高级篇)
离散数学的学习记录
VTK 初步 (1) ----- 可视化管线
LeetCode 1720. Decoding XORed Arrays (Simple)
PyTorch之训练技巧
LeetCode refers to the offer 21. Adjust the order of the array so that the odd numbers are in front of the even numbers (simple)
Tensorflow 2.0 使用流程详解
pytorch-08.加载数据集
棋类游戏-五子棋小游戏
STM32F407ZG TIM通用定时器
以STM32F103C6T6为例通过配置CubeMX实现EXIT外部中断
Radon 变换原理和应用