import json lt = [ {'name': '王宝强', 'age': 30}, {'name': '贾乃亮', 'age': 36}, {'name': '马蓉蓉', 'age': 33}, {'name': '宋吉吉', 'age': 40}, {'name': '李小璐', 'age': 43}, ] # json字符串<------dumps------python数据类型 # ------loads-------> # 包含json的类文件对象<------dump------python数据类型 # ------load-------> # 具有read()或者write()方法的对象就是类文件对象 # f = open(“a.txt”,”r”) f就是类文件对象 string = json.dumps(lt) print(type(string)) # <class 'str'> # json字符串 print(string) # [{"name": "u738bu5b9du5f3a", "age": 30}, {"name": "u8d3eu4e43u4eae", "age": 36}, {"name": "u9a6cu84c9u84c9", "age": 33}, {"name": "u5b8bu5409u5409", "age": 40}, {"name": "u674eu5c0fu7490", "age": 43}] obj = json.loads(string) print(type(obj)) # <class 'list'> json.dump(lt, open('json.txt', 'w', encoding='utf8')) obj = json.load(open('json.txt', 'r', encoding='utf8')) print(type(obj)) # <class 'list'> print(obj) # [{'name': '王宝强', 'age': 30}, {'name': '贾乃亮', 'age': 36}, {'name': '马蓉蓉', 'age': 33}, {'name': '宋吉吉', 'age': 40}, {'name': '李小璐', 'age': 43}]