1
私の 'data.json'ファイルからjson形式でデータを印刷しようとしています。私のPHPファイル(alldata.php)では、すべてのデータ(配列)をきれいに印刷することができました。しかし、あなたが私に手伝ってもらいたいのは、特定の配列名を取得する方法とオブジェクト/コンテンツです。URLから配列名を解析してJSONファイルからデータを取得する方法
マイalldata.phpは次のようになります。私は、このような '?alldata.php検索=プレイヤーの としてURLを使用してコンテンツを持つ配列例えば「プレイヤー」を取得することができますどのように、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"
}]
}
ここでのサンプルコード....
//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