How to access a member of a class which is inside another object from JSON using PHP

后端 未结 3 1964
孤城傲影
孤城傲影 2021-01-27 01:22

I have a JSON String like this

$test=\'{\"var1\":null,\"var3\":null,\"status\":{\"code\":150,\"message\":\"blah blah\"}}\';

I want to access th

3条回答
  •  天涯浪人
    2021-01-27 01:57

    You can use json_decode() for this task. Also, your input string should have quotes:

    $test='{"var1":null,"var3":null,"status":{"code":150,"message":"blah blah"}}';
    
    $responseObj = json_decode($test);
    
    echo $responseObj->status->code;
    

提交回复
热议问题