From b1a2f45484ffc70132964187bc3cb1a7b7a85bbd Mon Sep 17 00:00:00 2001 From: xldistance <819873074@qq.com> Date: Mon, 13 May 2019 11:57:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?json=E5=86=99=E5=85=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit json写入支持中文字符 --- vnpy/trader/utility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index f6c3dcdd..c25eaf73 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -97,8 +97,8 @@ def save_json(filename: str, data: dict): Save data into json file in temp path. """ filepath = get_file_path(filename) - with open(filepath, mode='w+') as f: - json.dump(data, f, indent=4) + with open(filepath, mode='w+',encoding = 'UTF-8') as f: + json.dump(data, f,sort_keys=True,indent =4,ensure_ascii=False) def round_to(value: float, target: float): From de8c29b38a119ca83343f61cc71543fb9f3018ea Mon Sep 17 00:00:00 2001 From: xldistance <819873074@qq.com> Date: Mon, 13 May 2019 12:01:40 +0800 Subject: [PATCH 2/2] Update utility.py --- vnpy/trader/utility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index c25eaf73..d5b6168f 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -84,7 +84,7 @@ def load_json(filename: str): filepath = get_file_path(filename) if filepath.exists(): - with open(filepath, mode='r') as f: + with open(filepath, mode='r',encoding = 'UTF-8') as f: data = json.load(f) return data else: