私のJSONがこれだとしましょう:
{
"achievement": [
{
"title": "All Around Submitter",
"description": "Get one piece of content approved in all six areas.",
"xp": 500,
"level_req": 1
},
{
"title": "World-wide Photo Journalist",
"description": "Get one photo approved in all six areas.",
"xp": 500,
"level_req": 1
},
{
"title": "Ready for Work",
"description": "Sign up and get validated",
"xp": 50,
"level_req": 1
},
{
"title": "Asian Pride",
"description": "Get ten pieces of content approved to a club in an Asian nation.",
"xp": 1500,
"level_req": 1
}
]
}
私のPHPコードはこれなので、そのjsonファイルをロードします...:
<?php
$string = file_get_contents("achievements.json");
$json_a=json_decode($string,true);
foreach ($json_a as $key => $value){
echo $value[0]['title'] . " <br />";
}
?>
ただし、最初の配列を出力するだけです。知っている。たった1。しかし、foreach
ループはどうですか?行ごとにループしないのはなぜですか?