How to iterate JSON in PHP -


in following json, want fetch customers phone , store in array:

{      "metainformation":{         "@totalresources":1,       "@totalpages":1,       "@currentpage":1    },    "customers":[         {            "@url":"https:\/\/url/customers\/1",          "address1":"mumbai",          "city":"mumbai",          "customernumber":"1",          "email":"xyz@gmail.com",          "name":"saurabh pradhan",          "organisationnumber":"",          "phone":"91xxx",          "zipcode":"45153"       }    ] } 

i tried using following keeps throwing me error "trying property of non-object in":

$customer_json = json_decode($api->getallcustomers());     $customer_json->customers[0]->phone; 

the problem php representation of json object not object. php uses associative arrays instead. convinient behavior use:

$customer_json = json_decode($api->getallcustomers(), true); $customer_json['customers'][0]['phone']; 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -