기록하는삶

[파이썬/Python] JSON(Javascript Object Notation) 파일 읽기, 한글 깨짐 현상 해결 본문

AI/파이썬(Python)

[파이썬/Python] JSON(Javascript Object Notation) 파일 읽기, 한글 깨짐 현상 해결

mingchin 2021. 11. 23. 02:10
728x90
반응형

파일을 열 때 encoding='UTF-8', json.dumps 로 파일을 불러올 때 ensure_ascii = False를 지정함으로써 한글 깨짐을 해결할 수 있다.

import json
import os
for x in os.listdir("D:\sample"):
    with open("D:\sample" + "/" + x, 'r', encoding='UTF-8') as f:

        json_data = json.load(f)

        print(x)
        print(1, json.dumps(json_data["transcription"]["Reading"], ensure_ascii = False) )

728x90
반응형