我正试图从这个json中提取特定数据:
[
{
"@context": "http://vocab.tokyometroapp.jp/context_odpt_Railway.jsonld",
"@id": "urn:ucode:_00001C000000000000010000030C46B1",
"@type": "odpt:Railway",
"owl:sameAs": "odpt.Railway:TokyoMetro.Yurakucho",
"dc:title": "有楽町",
"odpt:stationOrder": [
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Wakoshi",
"odpt:index": 0
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.ChikatetsuNarimasu",
"odpt:index": 1
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.ChikatetsuAkatsuka",
"odpt:index": 2
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Heiwadai",
"odpt:index": 3
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Hikawadai",
"odpt:index": 4
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.KotakeMukaihara",
"odpt:index": 5
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Senkawa",
"odpt:index": 6
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Kanamecho",
"odpt:index": 7
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Ikebukuro",
"odpt:index": 8
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.HigashiIkebukuro",
"odpt:index": 9
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Gokokuji",
"odpt:index": 10
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Edogawabashi",
"odpt:index": 11
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Iidabashi",
"odpt:index": 12
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Ichigaya",
"odpt:index": 13
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Kojimachi",
"odpt:index": 14
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Nagatacho",
"odpt:index": 15
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Sakuradamon",
"odpt:index": 16
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Yurakucho",
"odpt:index": 17
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.GinzaItchome",
"odpt:index": 18
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Shintomicho",
"odpt:index": 19
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Tsukishima",
"odpt:index": 20
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Toyosu",
"odpt:index": 21
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.Tatsumi",
"odpt:index": 22
},
{
"odpt:station": "odpt.Station:TokyoMetro.Yurakucho.ShinKiba",
"odpt:index": 23
}
],
"odpt:travelTime":
~~~~~~~~~~~~~~~~~~~~~snip~~~~~~~~~~~~~~~~~~
我想要获得的是电台名称,例如TokyoMetro.Yurakucho.ShinKiba
。
我试过了:
$json = file_get_contents($url.$info.$token);
$data = json_decode($json);
$stations = array($data->opdt.station);
var_dump($stations);
但我没有得到任何回报:
array(1) { [0]=> string(7) "station" }
有没有办法抓住这个特定的“列”数据?我更习惯于数据库查询。
非常感谢!
答案 0 :(得分:0)
由于有多个工作站,您必须遍历数组并将它们放在工作站名称数组中。
$json = file_get_contents($url.$info.$token);
$data = json_decode($json, true);
$stations = array();
foreach ($data[0]['odpt:stationOrder'] as $station) {
$name = $station['odpt:station'];
$parts = explode(':', $name);
$stations[] = $parts[1]; // Only care about the part after `odpt.Station:`
}
var_dump($stations);