I am in trouble with the bing’s json api.
Here is the json data i am receiving from api.bing.net/json.aspx:
{“SearchResponse”:{“Version”:”2.2″,”Query”:{“SearchTerms”:”news”},”Translation”:{“Results”:[{“TranslatedTerm”:”Noticias”}]}}}
I need to parse the TranslatedTerm value “Noticias” but it seems i have a problem with the json decode. I am using this..
result = j.loads(bytes)
print result['SearchResponse']['Translation']['Results']
And python gives me this:
[{u’TranslatedTerm’: u’Noticias’}]
If i add use it like this:
result[‘SearchResponse’][‘Translation’][‘Results’][“TranslatedTerm”]
python raises an error like
print result['SearchResponse']['Translation']['Results']["TranslatedTerm"]
TypeError: list indices must be integers
How can i get the ‘Noticias’ as a plain string? Much appriciated…
The translation
Resultsis a list – presumably because there can be many results.If you’re sure you’re only interested in the first result, you can do this: