1
我试图从我的'data.json'文件以json格式打印数据。用我的PHP文件(alldata.php),我可以获得所有数据(数组)的漂亮打印。但是,我希望你能帮助我的是如何获取特定的数组名称及其对象/内容。如何通过解析URL中的数组名称从JSON文件中获取数据
我alldata.php看起来是这样的:
{
"players": [
{
"name": "Marcos Alonso",
"position": "Left-Back",
"nationality": "Spain",
"marketValue": "9,000,000 €",
"created": "2017-04-15 10:04:58"
}],
"articles": [
{
"author": "Stephen Walter",
"title": "Disruptive stag party revellers thrown off plane at Manchester Airport",
"url": "http://www.telegraph.co.uk/news/2017/04/15/disruptive-stag-party-revellers-thrown-plane-manchester-airport/",
"publishedAt": "2017-04-15T09:25:10Z"
}],
land": [
{
"state": "Somewhr",
"found": "1889",
"area": "6,812",
"empl": "1,325",
"ppl": "16,842"
}]
}
在PHP中,我如何通过使用URL,如“alldata.php搜索=球员?” 得到一个阵列上,比如“运动员”与内容下面是一个代码示例....
//get content of the JSON API using file_get_contents()
$url = ('myJson.json');
$jsondata = file_get_contents($url);
//convert json object to php associative array
$data = json_decode($jsondata, true);
what do I do here to query the data.json file for a specific array?????
header('Content-Type: application/json; charset=UTF-8');
$json_string = json_encode($????????????, JSON_PRETTY_PRINT);
print $json_string;
感谢
是你的阵列一直在寻找具有多数据(同树)一样吗? – OldPadawan