1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# encoding=utf-8 import json l = [u"礼义廉耻", u"鹤发童颜"] j = json.dumps(l, ensure_ascii=False, indent=2) # 中文 print(j) ''' [ "礼义廉耻", "鹤发童颜" ] ''' l = json.loads(j) print(l) ''' ['礼义廉耻', '鹤发童颜'] ''' # 保存到文件 with open('List.txt', 'w', encoding='utf-8') as f: json.dump(l, f, ensure_ascii=False) # 从文件读取 with open('List.txt', 'r') as f: a = json.load(f) print(a) ''' ['礼义廉耻', '鹤发童颜'] ''' |