0

I am having a little trouble grabbing data from JSON code. I am trying to grab "Message" value under "innererror" from the json code which is "entity : An error has occurred."

$json = '{
  "odata.error":{
        "code":"",
        "message":{
            "lang":"en-US",
            "value":"The request is invalid."
            },
        "innererror":{
            "message":"entity : An error has occurred.",
            "type":"",
            "stacktrace":""
            }
  }
}';
$json_data = json_decode($json,true);

$main_response_data = $json_data['innererror'];


echo $main_response_data[0]['message'];

T Dev
  • 1
  • 1
  • Change it to `$main_response_data = $json_data['odata.error']['innererror'];` and `echo $main_response_data['message'];`. You will have to learn a bit more about objects and arrays. – nice_dev Jun 16 '22 at 18:34
  • Thank you for that! :-) I was reading over this ( https://www.opentechguides.com/how-to/article/php/205/php-nested-json.html ) – T Dev Jun 16 '22 at 18:37
  • See demo https://onlinephp.io/c/bf45d – nice_dev Jun 16 '22 at 18:37

0 Answers0