json좀도와주십시요 포이치문 중첩문돌리는데 잘안됩니다.. 채택완료
이건 json이구요..
{
"stashes":[
{
"accountName":"Nightlines",
"items":[{"verified":false,"w":2,"h":4,"ilvl":71,"icon":"http:url주소"
}
]
}
이건 php작성문입니다...
<?php
$jsonData=file_get_contents("poe.json");
$json=json_decode($jsonData, true);
$output="";
foreach($json['stashes'] as $stashes)
{
$output.="accountName: ".$stashes['accountName'].".<br>";
foreach($json['stashes'] as $items)
{
$output.="items : ".$stashes['items'].".<br>";
}
}
echo $output;
?>
이렇게하면
accountName : Nightlines.
items : Array.
items : Array.
items : Array.
items : Array.
items : Array.
items : Array.
.........
이런식으로 값자체가 데이터를 가져오질못하는데요
제가 문법이 틀린건가요..
"items":[{"verified":false,"w":2,"h":4,"ilvl":71,"icon":"http:url주소" 이부분을 가져오고싶은데 잘안되서그러는데 작은도움이도 좋으니 도움좀주세요
답변 7개
accountName: Nightlines.
items : verified =
items : w = 2
items : h = 4
items : ilvl = 71
items : icon = http:url주소
위 결과를 원하시면 아래 코드로 해보세요
</font></p><p><font face="Malgun Gothic" size="3">foreach($json['stashes'] as $stashes)</font></p><p><font face="Malgun Gothic" size="3">{</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>$output.="accountName: ".$stashes['accountName'].".
";</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>foreach($stashes['items'] as $items) </font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>foreach($items as $k => $v) </font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>{</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>$output.="items : ".$k." = ".$v."
";</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></p><p><font face="Malgun Gothic" size="3"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></p><p><font face="Malgun Gothic" size="3">}</font></p><p><font face="Malgun Gothic" size="3"></font></p><p><font face="Malgun Gothic" size="3">echo $output; </font></p><p><font face="Malgun Gothic" size="3">
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
</strong> </p><p>foreach($json['stashes'] as $stashes)</p><p>{</p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$output.="accountName: ".$stashes['accountName'].".
";</p><p><span class="Apple-tab-span" style="white-space:pre"> </span>foreach($stashes['items'] as $items) </p><p><span class="Apple-tab-span" style="white-space:pre"> </span>{</p><p><span class="Apple-tab-span" style="white-space:pre"> </span>$output.="items : ".$items['w'].".
";</p><p><span class="Apple-tab-span" style="white-space:pre"> </span>}</p><p>}</p><p>echo $output;</p><p><strong style="color: rgb(127, 127, 127); font-family: 돋움, Dotum, sans-serif; font-size: 12px;">
이렇게 해보세요^^
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
foreach ($json['stashes'][0] as $k => $v) {
if ($k == 'items')
foreach ($v[0] as $k1 => $v1)
echo $k1, '=>', $v1, '<br>';
else
echo $k, '=>', $v, '<br>';
}
답변에 대한 댓글 1개
// accountName=>Nightlines
lastCharacterName=>BigDixMemes
id=>a9a42a5dbda657f71b077ecd0692acce8d1d29c7dff3437e5ed8708f6cb8838f
stash=>LEVELING UNIQUES
stashType=>PremiumStash
public=>
이렇게뜨는데 왜 아이템은 출력이 안되는걸까요..
댓글을 작성하려면 로그인이 필요합니다.
이건 json이구요..
{
"stashes":[
{
"accountName":"Nightlines",
"items":[{"verified":false,"w":2,"h":4,"ilvl":71,"icon":"http:url주소"
}
]
}
이건 php작성문입니다...
<?php
$jsonData=file_get_contents("poe.json");
$json=json_decode($jsonData, true);
$output="";
foreach($json['stashes'] as $stashes => $v)
{
if($stashes == "accountName"){
$output.="accountName: ".$stashes['accountName'].".<br>";
}else{
foreach($v as $key => $val)
{
$output.="items : ".$key. $val".<br>";
}
}
}
echo $output;
?>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
<br />
{<br />
<br />
$output.="items : ".$stashes['items'].".<br>";<br />
<br />
}<br />
<br />
이부분을 수정해야합니다.<br />
foreach($json['items'] as $val) <br />
<br />
{<br />
<br />
$output.="items : ".$val['w']."/".$val['h']."<br>";<br />
<br />
}<br />
<br />
답변에 대한 댓글 1개
{
$output.="accountName : ".$stashes['accountName'].".<br>";
foreach($json['items'] as $val)
{
$output.="items : ".$val['w']."/".$val['h']."<br>";
}
}
echo $output;
이렇게하라는말씀이신가요?
출력결과가
accountName 값만나오는데 item값이나오질않아요
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인