使用python读取带有非ascii键的Json文件 - 如何引用键?

时间:2018-03-15 14:50:52

标签: python json unicode character-encoding

我有以下json:

{"Rotações": "string"}

这个python脚本带有相应的结果:

import json

with open('apaga.json') as jsonin:
    jsondict = json.load(jsonin)

print(jsondict)

> {'Rotações': 'string'}

所以我不知道如何调用此Rotações密钥,因为它对应于Rotações

以下不起作用:

print(jsondict['Rotações'.encode('latin')])

> KeyError: b'Rota\xe7\xf5es'

1 个答案:

答案 0 :(得分:0)

尝试解码为"utf-8"

<强>实施例

print(jsondict['Rotações'.decode('utf-8')])

python2.7

中测试