无法将数组/ json转换为数据。由于关键/价值对中的“关键”在父母身上是不同的,不知道如何得到它...理想情况下,我希望得到每个医院名称和每个医院名称得到时间(08:00)元素并使用CSS为其提供第二个元素的背景/文本颜色。
<?php
$data = '[{"name":"Anne Arundel Medical Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Baltimore Washington Medical Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Bon Secours Hospital","time":["","","",""],"color":[false,false,false,false]},{"name":"Carroll Hospital Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Franklin Square (MedStar)","time":["01:16","","",""],"color":["background-color:#ffff00;color:#000000;",false,false,false]},{"name":"Good Samaritan Hospital\u00a0(MedStar)","time":["","","",""],"color":[false,false,false,false]},{"name":"Greater Baltimore Medical Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Harbor Hospital (MedStar)","time":["","","",""],"color":[false,false,false,false]},{"name":"Harford Memorial Hospital (UMUCH)","time":["","","",""],"color":[false,false,false,false]},{"name":"Howard County General Hospital (JHM)","time":["","","",""],"color":[false,false,false,false]},{"name":"Johns Hopkins Bayview Medical Center","time":["","","","",""],"color":[false,false,false,false,false]},{"name":"Johns Hopkins Hospital","time":["","13:19","","",""],"color":[false,"background-color:#ff0000;color:#000000;",false,false,false]},{"name":"Johns Hopkins Hospital (Pediatric ED)","time":["","","","",""],"color":[false,false,false,false,false]},{"name":"Mercy Medical Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Midtown (UM)","time":["","","",""],"color":[false,false,false,false]},{"name":"Northwest Hospital","time":["","","",""],"color":[false,false,false,false]},{"name":"R Adams Cowley Shock Trauma Center","time":["","","","","",""],"color":[false,false,false,false,false,false]},{"name":"Sinai Hospital of Baltimore","time":["","","","",""],"color":[false,false,false,false,false]},{"name":"St. Agnes Hospital","time":["","","",""],"color":[false,false,false,false]},{"name":"St. Joseph\u2019s\u00a0 (UM)","time":["","","",""],"color":[false,false,false,false]},{"name":"Union Memorial Hospital\u00a0 (MedStar)","time":["","","",""],"color":[false,false,false,false]},{"name":"University of Maryland Medical Center","time":["","","",""],"color":[false,false,false,false]},{"name":"Upper Chesapeake Medical Center (UMUCH)","time":["","","",""],"color":[false,false,false,false]}]';
$json = json_decode($data, true);
echo '<pre>';
echo print_r($json);
echo '</pre>';
//exit;
foreach($json[?] as $item) {
echo 'Name: ' . $item[?][1] . '<br />';
echo 'Time: ' . $item[?][2] . '<br />';
echo 'color: ' . $item[?][3] . '<br />';
}
?>
答案 0 :(得分:0)
您的JSON数据细分为
{
"" : [ true ],
"00:06" : {
"background-color:#ff6600;color:#000000;" : true
},
"00:11" : {
"background-color:#ffff00;color:#000000;" : true
},
"00:16" : {
"background-color:#ffff00;color:#000000;" : true
},
"00:17" : {
"background-color:#ff0000;color:#000000;" : true
},
"01:17" : {
"background-color:#ffff00;color:#000000;" : true
},
"01:30" : {
"background-color:#ffff00;color:#000000;" : true
},
"02:03" : {
"background-color:#000000;color:#ffffff;" : true
},
"02:37" : {
"background-color:#ffff00;color:#000000;" : true
},
"03:03" : {
"background-color:#ffff00;color:#000000;" : true
},
"14:44" : {
"background-color:#ff0000;color:#000000;" : true
},
"Anne Arundel Medical Center" : [ true ],
"Baltimore Washington Medical Center" : [ true ],
"Bon Secours Hospital" : [ true ],
"Carroll Hospital Center" : [ true ],
"Franklin Square (MedStar)" : [ true ],
"Good Samaritan Hospital(MedStar)" : [ true ],
"Greater Baltimore Medical Center" : [ true ],
"Harbor Hospital (MedStar)" : [ true ],
"Harford Memorial Hospital (UMUCH)" : [ true ],
"Howard County General Hospital (JHM)" : [ true ],
"Johns Hopkins Bayview Medical Center" : [ true ],
"Johns Hopkins Hospital" : [ true ],
"Johns Hopkins Hospital (Pediatric ED)" : [ true ],
"Mercy Medical Center" : [ true ],
"Midtown (UM)" : [ true ],
"Northwest Hospital" : [ true ],
"R Adams Cowley Shock Trauma Center" : [ true ],
"Sinai Hospital of Baltimore" : [ true ],
"St. Agnes Hospital" : [ true ],
"St. Josephs (UM)" : [ true ],
"Union Memorial Hospital (MedStar)" : [ true ],
"University of Maryland Medical Center" : [ true ],
"Upper Chesapeake Medical Center (UMUCH)" : [ true ]
}
正如您所看到的,时间与医院之间没有相关性。