以下.json文件中的数据。我想阅读并打印数据。
{" employees" :[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName": "Jones"}
]};
答案 0 :(得分:2)
您的json文件 ("/something/abc.json")
{"employees":[
{
"firstName":"Ray",
"lastName":"Villalobos",
"joined":2012
},
{
"firstName":"John",
"lastName":"Jones",
"joined":2010
}
]}
您的PHP代码,
<?php
$string = file_get_contents("/something/abc.json");
$arr = json_decode($string,true);
foreach($arr as $a)
{
// Iteration
}
?>