Decoding Particular Element of JSON In PHP -
i trying decode json
i reading json through stomp. there different json datasets need work out json dataset has come through. reading title.
however there 1 particular dataset having trouble reading
foreach (json_decode($msg->body,true) $event) { if(isset($event['schemalocation'])) { $schedule_id=($event['schedule']['schedule_start_date']); $signalling_id=($event['schedule']['schedule_segment']['signalling_id']); echo $schedule_id; }
in above example isset function works fine , $schedule_id obtains right answer
however $signalling_id gives error of undefined index:
here dump of part of json (its rather long............).the piece of json signalling_id towards end of json. variable signalling_id appreciated.
array(7) { ["schemalocation"]=> string(72) "http://xml.networkrail.co.uk/ns/2008/train itm_vstp_cif_messaging_v1.xsd" ["classification"]=> string(8) "industry" ["timestamp"]=> string(13) "1410374918000" ["owner"]=> string(12) "network rail" ["originmsgid"]=> string(47) "2014-09-10t18:48:38-00:00vstp.networkrail.co.uk" ["sender"]=> array(3) { ["organisation"]=> string(12) "network rail" ["application"]=> string(4) "tops" ["component"]=> string(4) "vstp" } ["schedule"]=> array(11) { ["schedule_id"]=> string(0) "" ["transaction_type"]=> string(6) "create" ["schedule_start_date"]=> string(10) "2014-09-10" ["schedule_end_date"]=> string(10) "2014-09-10" ["schedule_days_runs"]=> string(7) "0010000" ["applicable_timetable"]=> string(1) "n" ["cif_bank_holiday_running"]=> string(1) " " ["cif_train_uid"]=> string(6) "w64017" ["train_status"]=> string(1) "1" ["cif_stp_indicator"]=> string(1) "o" ["schedule_segment"]=> array(1) { [0]=> array(20) { ["signalling_id"]=> string(4) "5y75" ["uic_code"]=> string(0) "" ["atoc_code"]=> string(0) "" ["cif_train_category"]=> string(2) "ee" ["cif_headcode"]=> string(0) "" ["cif_course_indicator"]= ............................................
schedule_segment array, instead of
['schedule']['schedule_segment']['signalling_id']);
that should be
['schedule']['schedule_segment'][0]['signalling_id']);
Comments
Post a Comment