From 632b413490941402d9615d0007d244313190a75a Mon Sep 17 00:00:00 2001 From: f18326186224 Date: Thu, 30 Nov 2023 03:40:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update_data.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/update_data.py b/update_data.py index 1952a99..f714f45 100644 --- a/update_data.py +++ b/update_data.py @@ -1,3 +1,17 @@ # 更新data.json文件 +import json +import requests + +with open('data.json', mode='r+',encoding='utf-8') as my_file: + text = my_file.read() + data = json.loads(text) + # 新增数据 + data['data'].append({ + 'name': '新数据', + 'age': 18 + }) + # 写入文件 + with open('data.json', mode='w+',encoding='utf-8') as my_file: + my_file.write(json.dumps(data)) print('已更新数据!') \ No newline at end of file