以下JSON如何解析以下JSON在PHP如何解析在PHP
[
{ "user":"John", "age":22, "country":"United States" },
{ "user":"Will", "age":27, "country":"United Kingdom" },
{ "user":"Abiel", "age":19, "country":"Mexico" },
{ "user":"Rick", "age":34, "country":"Panama" },
{ "user":"Susan", "age":23, "country":"Germany" },
{ "user":"Amy", "age":43, "country":"France" }
]
我用下面的代碼,這一點,但它沒有工作
$jsonData = file_get_contents("http://localhost/attendance1/a.json");
$phpArray = json_decode($jsonData, true);
echo $phpArray;
foreach ($phpArray as $key => $value) {
echo "<h2>$key</h2>";
foreach ($value as $k => $v) {
echo "$k | $v <br />";
}
}
這不是有效的JSON。 – Barmar
數組應該用''[']'而不是'{...}'包圍。 – Barmar
這不是有效的JSON字符串。 – bspellmeyer