Possible Duplicate:
How to parse a JSON string using PHP
this is my data object
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt"
},
{
"translatedText": "Hallo Berlin"
}
]
}
}
how do I parse this using PHP?
this is a jsonObject that contains jsonObject("data") that contains jsonArray that contains jsonObjects at each index that contains key/value "translatedText"
this is what I have and my assumption
$jsonResult = json_decode($data);
$translated_text = $jsonResult->data->translations[0]->translatedText;`
asked Nov 26, 2012 at 19:16
3 Answers 3
$array = json_decode($json_element, true);
to make associative array.
answered Nov 26, 2012 at 19:19
Comments
I'm think this is what it would be. json_decode does not parse to a PHP object, but to just an array.
$jsonResult = json_decode($data);
$translated_text = $jsonResult['data']['translations'][0]['translatedText'];
answered Nov 26, 2012 at 19:24
Comments
$array = json_decode($json_element);
answered Nov 26, 2012 at 19:17
Comments
lang-php
json_decode()
?var_dump($jsonResult);
?