.json 文件存在问题,其中包含西里尔符号。如何将 CP1251 转换为 UTF-8?(temp_data.decode('utf-8')没有效果,如.dumps 中的ensure_ascii=False)
import json
def load_data(filepath):
with open(filepath, 'r') as f:
temp_data = json.load(f)
return temp_data
def pretty_print_json(d):
out_json = json.dumps(d, sort_keys=True, indent=4, separators = (',', ': '))
print(out_json)
if __name__ == '__main__':
print("Enter the path to .json file: ")
in_path = input()
print("There are pretty printed json format: ")
pretty_print_json(load_data(in_path))