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;`
share|improve this question

1  
Have you tried: json_decode()? – PeeHaa yesterday
Have you tried: var_dump($jsonResult);? – PeeHaa yesterday
1  
Actually, this is a fair question. If you come to PHP from other languages PHP handles JSON differently. There are no jsonArray or jsonObject types in PHP (like in Java or C#). – Mathew Foscarini yesterday
feedback

closed as exact duplicate by PeeHaa, tereško, Madara Uchiha, Baba, Kate Gregory yesterday

This question covers exactly the same content as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

3 Answers

$array = json_decode($json_element, true);

to make associative array.

share|improve this answer
feedback

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'];
share|improve this answer
feedback
$array = json_decode($json_element);
share|improve this answer
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.