I’m new to Python and JSON, so I’m sorry if I sound clueless. I’m getting the following result from the Google Translate API and want to parse out the value of “translatedText”:
{
"data": {
"translations": [
{
"translatedText": "Toute votre base sont appartiennent à nous"
}
]
}
}
This response is simply stored as a string using this:
response = urllib2.urlopen(translateUrl)
translateResponse = response.read()
So yeah, all I want to do is get the translated text and store it in a variable. I’ve searched the Python Docs but it seems so confusing and doesn’t seem to consider JSON stored as a simple string rather than some super cool JSON object.
You can parse the text into an object using the
jsonmodule in Python >= 2.6: