Python 之json模块

一、函数列表

函数描述
json.dumps 将 Python 对象编码成 JSON 字符串
json.loads 将已编码的 JSON 字符串解码为 Python 对象

二、示例

#!/usr/bin/python
import json

data = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]

json = json.dumps(data)
print json
#!/usr/bin/python
import json

jsonData = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

text = json.loads(jsonData)
print text

python 原始类型向 json 类型的转化对照表:

PythonJSON
dict object
list, tuple array
str, unicode string
int, long, float number
True true
False false
None null
原文地址:https://www.cnblogs.com/yang-2018/p/12768346.html