json是一种轻量级的数据交换格式。在python中使用json需要先导入json包

json字符串:符合json格式的字符串叫做json字符串

json的优点:

1.json序列化

import json

>>> di = {"name":"xiaosan","age":19,"sex":1}
>>> json.dumps(di)
'{"name": "xiaosan", "age": 19, "sex": 1}'

紧凑一点

>>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
'[1,2,3,{"4":5,"6":7}]'

2.json反序列化

>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
['foo', {'bar': ['baz', None, 1.0, 2]}]

python3.7 入门教程

Python 准备工作(1) Python 基本数据类型 Number(2) Python 字符串 str(3) Python 列表List(4) Python 元组tuple(5) Python 集合set(6) Python 字典 dict(7) Python 变量(8) Python 运算符(9) Python 条件语句(10) Python 循环语句(11) Python 包 模块(12) Python 函数一(13) Python 函数二(14) Python 面向对象(15) Python 正则(16) Python json(17) Python 枚举(18) Python 闭包(19) Python 装饰器(20) Python 杂记(21) Python with(22)