1 import json 2 3 4 a = [{'a':1},{'b':'张三'}] 5 b = json.dumps(a) 6 7 # with open('a.json','w',encoding='utf-8') as fp: 8 # # fp.write(b) 9 # #json内置函数直接写入 10 # json.dump(a,fp,ensure_ascii=False)#a是文件名,如果有中文ensure_ascii=False,不然会以Unicode的编码存储 11 # # json_str = '[{"a": 1}, {"b": "张三"}]' 12 # p_str = json.loads(json_str) 13 # for x in p_str: 14 # print(x) 15 # with open('a.json','r',encoding='utf-8') as fp: 16 # x = json.load(fp) 17 # for y in x: 18 # print(y)