【json】json转换Unicode变为中文

1、场景

从接口读取数据写入文件时,在文件中显示的是Unicode字符

 

2、处理方法

import json


def read_json_file(file_path):
    try:
        with open(file_path, mode='r', encoding='utf-8') as fp:
            result = json.load(fp)
    except Exception as e:
        raise e
    else:
        return result


def dump_json_file(file_path, data):
    try:
        with open(file_path, 'w') as f:
            json.dump(data, fp, indent=4, ensure_ascii=False)
    except Exception as e:
        raise e
    else:
        return True

主要参数是

ensure_ascii=False
posted @ 2022-10-26 10:06  代码诠释的世界  阅读(951)  评论(0编辑  收藏  举报