我在使用 bing 的 json api 时遇到了麻烦。
这是我从 api.bing.net/json.aspx 收到的 json 数据:
{"SearchResponse":{"Version":"2.2","Query":{"SearchTerms":"news"},"Translation":{"Results":[{"TranslatedTerm":"Noticias"}]}} }
我需要解析 TranslatedTerm 值“Noticias”,但似乎我的 json 解码有问题。我正在使用这个..
result = j.loads(bytes)
print result['SearchResponse']['Translation']['Results']
而python给了我这个:
[{u'TranslatedTerm': u'Noticias'}]
如果我添加这样使用它:
结果['SearchResponse']['Translation']['Results']["TranslatedTerm"]
python引发一个错误,如
print result['SearchResponse']['Translation']['Results']["TranslatedTerm"]
TypeError:列表索引必须是整数
如何将“Noticias”作为纯字符串获取?非常赞赏...