json 데이터 가져오기 문법좀 알려주세요
본문
"stashes" : -[
- -{
- "accountName" : 5a4oK,
- "lastCharacterName" : ,
- "id" : 6e744b0f76179835e1f681ce81c513ea190cb021b34eaacafe4c3d4f6990395f,
- "stash" : What i need,
- "stashType" : PremiumStash,
- "items" : -[
- -{
- "verified" : false,
- "w" : 2,
- "h" : 4,
- "id" : 176b5e6f7af0a5bb4b48d7fdafa47501a179f4ea095815a58c82c4b5244b3cdb,
- "x" : 10,
- "y" : 0,
}
]
- -{
- php코드는
- <?php$jsonData=file_get_contents("poe.json");$json=json_decode($jsonData, true);$output="";foreach($json['stashes'] as $stashes){$output.="items : ".$stashes['items'].".<br>";}echo $output;?>
- $output.="stash: ".$stashes['stash'].".<br>";
- 이렇게 하나인 값은 그냥 값이 제대로뜨는데
- items 안에 또 값이 있는건 어떻게 할줄을몰라서..
이렇게하면 array값이 뜨는데.. - item안에 저 6개의 값을도 출력시킬려면 어떻게 해야하는지 잘 모르겠습니다 도움좀 부탁드립니다
답변 3
echo print_r($stashes['items']); 해서 배열 데이타구조를 확인해보세요
foreach($json['stashes'] as $stashes)
{
if(count($stashes['items']) > 1) {
foreach($stashes['items'] as $_key=>$_val)
{
$output .= "items (".$_key.") : ".$_val."<br>";
}
} else {
$output.="items : ".$stashes['items'].".<br>";
}
}
echo $json->stashes->items->verified;
echo $json->stashes->items->w;
답변을 작성하시기 전에 로그인 해주세요.