나는 아래 json을 데이터베이스 테이블에서 값을 얻도록 구성했다. 이제 json 아래에서 PHP의 un-ordered list로 인쇄하고 싶습니다. 어떻게이 목록을 json 아래에 인쇄 할 수 있습니까?이 json 문자열을 인쇄하려면 어떻게해야합니까?
내 배열 및 예상 출력입니다.
{
"id": "6",
"name": "aaaaa",
"actove_from": "2000",
"firstlevelrelations": {
"1": {
"name": "bbbbb",
"active_from": "1990"
},
"5": {
"name": "cccccc",
"active_from": "2003"
},
"4": {
"name": "dddddd",
"active_from": "1992",
"2": {
"name": "fffff",
"active_from": "1990"
}
},
"7": {
"name": "ggggg",
"active_from": "2015"
},
"9": {
"name": "hhhhhh",
"active_from": "1990",
"10": {
"name": "yyyyy",
"active_from": "1997"
}
}
}
}
ouptut : 당신 인덱스 이름 여기
foreach($jsonvar as $key=>$value){
//if it is just a simple value
$valuesInsideYourJson = $value;
//if it is an array of other objects.
if(is_array($valuesInsideYourJson)){
foreach($valuesInsideYourJson as $val){
// this in inside the firstlevelrelation
// do whatever you want
}
}
}
당신이 원시 데이터에 대한 액세스를 변경할 수있는 경우
<ul>
<li>aaaaaa</li>
<li>2000</li>
<ul>
<li>bbbbbb</li>
<li>1990</li>
<li>ccccc</li>
<li>2003</li>
<li>dddddd</li>
<li>1992
<ul>
<li>fffff</li>
<li>1990</li>
</ul>
</li>
<li>gggggg</li>
<li>2015</li>
<li>hhhhhh</li>
<li>1990
<ul>
<li>yyyyyy</li>
<li>1997</li>
</ul>
</li>
</ul>
</ul>
이
는 [json_decode (http://php.net/manual/en/function.json-decode.php)가 얻어 JSON 인코딩 된 문자열을 PHP 연관 배열로 변환합니다. 이제 배열을 반복하고 HTML을 출력하십시오. – bloodyKnuckles
배열을 반복 할 때 하나씩 인쇄하는 대신 단일 루프 실행에서 두 개의 목록 (li)을 인쇄하려고합니다. – user3452547