Python 解析 JSON

Python 解析 JSON

JSON (JavaScript Object Notation) 是一种轻量级的数据交换格式。Python3 中可以使用 json 模块来对 JSON 数据进行编解码,主要包含了下面4个操作函数:

提示:所谓类文件对象指那些具有read()或者 write()方法的对象,例如,f = open('a.txt','r'),其中的f有read()方法,所以f就是类文件对象。

在json的编解码过程中,python的原始类型与JSON类型会相互转换,具体如下:

Python编码为JSON类型转换对应表:

Python JSON
dict object
list,tuple array
str string
int, float, int- & float-derived Enums number
True true
False false
None null

JSON 解码为Python类型转换对应表:

JSON Python
object dict
array list
string str
number (int) int
number (real) float
true True
false False
null None
posted @ 2021-09-03 10:49  Star-Hitian  阅读(78)  评论(0编辑  收藏  举报