Access data in JSON via PHP -
i trying access data generated via directory services database creating ics files being sent website via json encoding.
there multiple files or unknown amount being generated. main issue @ point, need parse information out of json files ics files.
what stuck @ moment reading information in json files.
the json files this:
{ "smsdata": { "date": 20170817062448, "person": { "data":[{ "person": 321654978, "information": "person information" },{ "person": 3216549, "information": "person information" }] }}
what trying dig deep , person
, information
data out ics file.
what have @ moment in php display data see if accessing correct data is:
$str = '../filename/test.json'; // location of files $contents = file_get_contents($str); // information file $decode = json_decode($contents, true); // creates json array //array loop foreach($decode $key => $value){ echo $value["person"]. " -> " . $value["information"]. "<br>"; // should display information needed print_r ($value); // test dump of data }
i'm aware i'm not digging deep enough. found resourse helpful: how extract data json php?, convert , loop through json php , javascript arrays/objects. believe ical parser of great use not sure how use @ stage.
i want make sure i'm reading correct data now, next step create .ics files person , information data.
thank help.
(btw, i've been using php couple months)
you correct, not starting loop on correct array member.
$contents = '{ "smsdata": { "date": 20170817062448, "person": { "data":[{ "person": 321654978, "information": "person information" },{ "person": 3216549, "information": "person information" }] } } }'; $decode = json_decode($contents, true); print_r($decode); foreach($decode['smsdata']['person']['data'] $value){ echo $value["person"]. " -> " . $value["information"]. "<br>"; }
results
321654978 -> person information<br> 3216549 -> person information<br>
Comments
Post a Comment