Python | |
---|---|
object | dict |
array | list |
string | str |
number(int) | int, long |
number(real) | float |
true | True |
false | False |
null |
import json json_str = ''' [{"province": "美国", "currentConfirmedCount": 1179041, "confirmedCount": 1643499}, {"province": "英国", "currentConfirmedCount": 222227, "confirmedCount": 259559}] ''' # 1.把json字符串转换为python数据 rs = json.loads(json_str) print(rs) # 2.把json格式文件转换为python类型的数据 with open('data/test.json') as fp: python_list = json.load(fp) print(python_list)
-
Python类型数据转换为json字符串 json.dumps(obj)
-
Python类型数据以json格式写入文件 json.dump(obj, fp)