Merge pull request #1692 from xldistance/patch-15

json写入支持中文字符
This commit is contained in:
vn.py 2019-05-17 16:09:19 +08:00 committed by GitHub
commit 16591ee97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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:
@ -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):