配列/ jsonをデータに変換するのに問題があります。キー/値のペアの 'キー'が親のImと違うので、それを取得する方法が...理想的には私は各病院の名前を取得し、各病院の名前は時間(08:00)要素CSSを使用して2番目の要素の背景色/テキスト色を設定します。php JSONを後のDB挿入の変数にロードする
<?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 />';
}
?>
json配列が適切なJSONエンコード文字列のように見えません – rak007
@PaulCrovella配列の各エントリにはキーはありません。私の意見ではこれほど使用できません – rak007
タイトルを取得する方法が不思議ですが、この「データ」からブランドと説明を削除します。存在していないような$ json [1]から... – jeroen