【问题标题】:Read Json file with non-ascii keys with python - how to reference the keys? [duplicate]使用 python 读取具有非 ascii 键的 Json 文件 - 如何引用键? [复制]
【发布时间】:2018-03-15 14:50:52
【问题描述】:

我有以下 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'

【问题讨论】:

    标签: python json unicode character-encoding


    【解决方案1】:

    尝试解码为"utf-8"

    例如:

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

    python2.7

    中测试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2020-10-21
      相关资源
      最近更新 更多