json decode in php -
i have following json string , want retrieve email address it. how do in php?
{"communications":{"communication":[{"@array":"true","@id":"23101384","@uri":"xyz/v1/communications/1111","household":{"@id":"111111","@uri":"xyz/v1/households/5465465"},"person":{"@id":"","@uri":""},"communicationtype":{"@id":"1","@uri":"xyz/v1/communications/communicationtypes/1","name":"home phone"},"communicationgeneraltype":"telephone","communicationvalue":"1111","searchcommunicationvalue":"2693240758","listed":"true","communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:40:02"},{"@array":"true","@id":"11111","@uri":"xyz/v1/communications/111111111","household":{"@id":"14436295","@uri":"xyz/v1/households/11111"},"person":{"@id":"2222222","@uri":"xyz/v1/people/22222222"},"communicationtype":{"@id":"2","@uri":"xyz/v1/communications/communicationtypes/2","name":"work phone"},"communicationgeneraltype":"telephone","communicationvalue":"11111","searchcommunicationvalue":"789787987","listed":"false","communicationcomment":null,"createddate":"2009-08-09t15:49:27","lastupdateddate":"2009-08-11t23:40:02"},{"@array":"true","@id":"11111","@uri":"xyz/v1/communications/11111","household":{"@id":"1111","@uri":"xyz/v1/households/1111"},"person":{"@id":"244404","@uri":"xyz/v1/people/1111"},"communicationtype":{"@id":"3","@uri":"xyz/v1/communications/communicationtypes/3","name":"mobile"},"communicationgeneraltype":"telephone","communicationvalue":"22222","searchcommunicationvalue":"5475454","listed":"true","communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:40:02"},{"@array":"true","@id":"15454","@uri":"xyz/v1/communications/111111","household":{"@id":"14436295","@uri":"xyz/v1/households/1111"},"person":{"@id":"244444474","@uri":"xyz/v1/people/111111"},"communicationtype":{"@id":"4","@uri":"xyz/v1/communications/communicationtypes/4","name":"email"},"communicationgeneraltype":"email","communicationvalue":"email@needthis.com","searchcommunicationvalue":"email@needthis.com","listed":"true","communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:39:06"}]}}
another twist on how inerte did access like:
$json_object = '{"communications": {"communication": [{"@array":"true","@id":"23101384","@uri":"xyz/v1/communications/1111","household": {"@id":"111111","@uri":"xyz/v1/households/5465465"}, "person": {"@id":"","@uri":""}, "communicationtype":{"@id":"1","@uri":"xyz/v1/communications/communicationtypes/1","name":"home phone"}, "communicationgeneraltype":"telephone","communicationvalue":"1111","searchcommunicationvalue":"2693240758", "listed":"true","communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:40:02"}, {"@array":"true","@id":"11111","@uri":"xyz/v1/communications/111111111","household": {"@id":"14436295","@uri":"xyz/v1/households/11111"}, "person": {"@id":"2222222","@uri":"xyz/v1/people/22222222"}, "communicationtype": {"@id":"2","@uri":"xyz/v1/communications/communicationtypes/2","name":"work phone"}, "communicationgeneraltype":"telephone","communicationvalue":"11111","searchcommunicationvalue":"789787987","listed":"false", "communicationcomment":null,"createddate":"2009-08-09t15:49:27","lastupdateddate":"2009-08-11t23:40:02"}, {"@array":"true","@id":"11111","@uri":"xyz/v1/communications/11111","household": {"@id":"1111","@uri":"xyz/v1/households/1111"}, "person":{"@id":"244404","@uri":"xyz/v1/people/1111"}, "communicationtype":{"@id":"3","@uri":"xyz/v1/communications/communicationtypes/3","name":"mobile"}, "communicationgeneraltype":"telephone","communicationvalue":"22222","searchcommunicationvalue":"5475454","listed":"true", "communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:40:02"}, {"@array":"true","@id":"15454","@uri":"xyz/v1/communications/111111","household":{"@id":"14436295","@uri":"xyz/v1/households/1111"}, "person":{"@id":"244444474","@uri":"xyz/v1/people/111111"}, "communicationtype":{"@id":"4","@uri":"xyz/v1/communications/communicationtypes/4","name":"email"}, "communicationgeneraltype":"email","communicationvalue":"email@needthis.com","searchcommunicationvalue":"email@needthis.com","listed":"true", "communicationcomment":null,"createddate":"2008-11-10t12:31:26","lastupdateddate":"2009-08-11t23:39:06"} ] } }'; $json_decoded = json_decode($json_object); echo "email: ".$json_decoded->communications->communication[3]->communicationvalue."<br />";
Comments
Post a Comment