UnicodeDecodeError: 'cp950' codec can't decode byte 解決方法

 

這是編碼問題,只要在讀取檔案的時候將原本的:

import json
input_file = open("info.json")
json_array = json.load(input_file)
for item in json_array:
   
print(item['_index'])

 

改成:

import json
input_file = open("info.json", encoding='utf-8')
json_array = json.load(input_file)
for item in json_array:
   
print(item['_index'])

 

 

就不會出錯了。

arrow
arrow
    全站熱搜

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()