Read json in python after encoding it

前端 未结 2 1300
南旧
南旧 2021-01-27 17:52

I have a json file that fails loading when I use the following code:

indices_json_path = \'file.json\'
with open(indices_json_path) as json_data:
    d = json.lo         


        
相关标签:
2条回答
  • 2021-01-27 17:57

    This solved the problem:

    with io.open(indices_json_path,'r', encoding='UTF-16-LE') as json_data:
        d = json.load(json_data)
    
    0 讨论(0)
  • 2021-01-27 18:08

    I would probably guess it is an encoding error, try:

    import io
    with io.open(indices_json_path,'r',encoding='utf8') as json_data:
        d = json.load(json_data)
    
    0 讨论(0)
提交回复
热议问题