php - foreach on Json is not working though var_dump is showing the array -
i'm trying run foreach on decoded array, follows:
array:
[ { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] }, { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] }, { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] }, { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] }, { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] }, { "addresses": [ { "city": "hod hash", "country": "israel", "countrycode": "", "localizedlabel": "work", "originallabel": "_$!<work>!$_", "state": "", "street": "shahaf6\nsec", "zip": 41343 } ], "birthday": "2006-12-2712: 00: 00+0000", "creationdate": "2016-12-2711: 30: 00+0000", "emails": [ { "address": "nir@kfs.fin", "localizedlabel": "lab", "originallabel": "lab" }, { "address": "furt@hdf.cin", "localizedlabel": "icloud", "originallabel": "icloud" } ], "job": { "company": "layer", "jobtitle": "" }, "modificationdate": "2016-12-2711: 30: 00+0000", "name": { "compositename": "test contant", "firstname": "test", "lastname": "contant", "middlename": "" }, "notes": "guy yd hcgd g\n", "phones": [ { "localizedlabel": "home", "number": "054-8862488", "originallabel": "_$!<home>!$_" }, { "localizedlabel": "iphone", "number": "054-7532635", "originallabel": "iphone" }, { "localizedlabel": "work", "number": "03-4214532", "originallabel": "_$!<work>!$_" } ], "recordid": "908", "source": { "sourceid": 0, "sourcetype": "" }, "websites": [ "www.layer.com", "google.com" ] } ]
the array in variable $inputdata
.
then:
$decodedcontact = json_decode($inputdata['contact']); //disregard contact it's coming body key: contact , value: array`
when run:
foreach ($decodedcontact $contact){ echo $contact.'<br>'; }
i get:
object of class stdclass not converted string
when var_dump($decodeddata);
looks great... :\
if contact
stdclass
can't echo
it. can use var_dump
on object (to see it's values) or echo
values:
var_dump($contact);
or
echo $contact->birthday;
Comments
Post a Comment