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 |
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/p/15222126.html

浙公网安备 33010602011771号