Simplejson を使用して Python で JSON オブジェクトを抽出しようとしています。しかし、次のエラーが発生します。
Traceback (most recent call last):
File "Translator.py", line 42, in <module>
main()
File "Translator.py", line 38, in main
parse_json(trans_text)
File "Translator.py", line 27, in parse_json
result = json['translations']['translatedText']
TypeError: list indices must be integers, not str
これは私のJSON
オブジェクトのように見えます、
{'translations': [{'translatedText': 'fleur'}, {'translatedText': 'voiture'}]}
これは私のpythonコードです。
def parse_json(trans_text):
json = simplejson.loads(str(trans_text).replace("'", '"'))
result = json['translations']['translatedText']
print result
それについて何か考えはありますか?