Python - UnicodeDecodeError:“charmap”编解码器在位置44无法解码字节0x81:字符映射到

时间:2021-08-07 10:14:03

Using pandas on Python 3 Jupyter notebook, I got

我在Python 3 Jupyter笔记本上使用了熊猫

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 44: character maps to

UnicodeDecodeError:“charmap”编解码器在位置44:字符映射到的位置无法解码字节0x81

error while trying to read a json file that looks like this:

当尝试读取如下所示的json文件时出错:

{
    "Test1": {
        "A": "攻撃を続ける",
        "B": "残り資源",
        "C": "残りの資源を得るため小隊を修理し戦闘を続けろ:"
    },
    "Test2": {
        "D": "{x} 日目",
        "E": "CC レベル {x}",
        "F": "本当にこれから全てのデバイスでこの基地を使用しますか?",
        "G": "この{social_network}アカウントには2つの基地が存在してます。基地の数は一人のプレイヤーにつき一つに限定されています。基地を選択するか、キャンセルしてください。",
    }
}

Any idea how to solve this?

你知道怎么解决这个问题吗?

See full error message here

在这里查看完整的错误消息。

import pandas as pd

json_df = pd.read_json('input.json')
json_df

EDIT: I have also tried reading the json with the JSON module, it still the same error.

编辑:我也试过用json模块读取json,它还是一样的错误。

1 个解决方案

#1


1  

Your .json file is encoded as UTF-8. pd.read_json tries to decode it as CP1252. You need to make it decode it as UTF-8:

您的.json文件被编码为UTF-8。pd。read_json试图将其解码为CP1252。你需要让它解码成UTF-8:

import pandas as pd

json_df = pd.read_json('input.json', encoding='UTF-8')
json_df

#1


1  

Your .json file is encoded as UTF-8. pd.read_json tries to decode it as CP1252. You need to make it decode it as UTF-8:

您的.json文件被编码为UTF-8。pd。read_json试图将其解码为CP1252。你需要让它解码成UTF-8:

import pandas as pd

json_df = pd.read_json('input.json', encoding='UTF-8')
json_df