使用api数据创建html表


Creating an html table using api data

我从php中的api源请求了一些数据,我可以在页面上显示这些数据。其格式如下。我想把这些数据放在一个html表中,以便用户可读。例如,我想从这个数据中只向用户显示"莱斯特城0斯托克城FC 1"这一部分。我应该用什么,你能给我一个至少从哪里开始的想法吗?

{"_links":[{"self":"http://api.football-data.org/alpha/soccerseasons/354/fixtures"},{"soccerseason":"http://api.football-data.org/alpha/soccerseasons/354"}],"count":10,"fixtures":[{"_links":{"self":{"href":"http://api.football-data.org/alpha/fixtures/137842"},"soccerseason":{"href":"http://api.football-data.org/alpha/soccerseasons/354"},"homeTeam":{"href":"http://api.football-data.org/alpha/teams/338"},"awayTeam":{"href":"http://api.football-data.org/alpha/teams/70"}},"date":"2015-01-17T15:00:00Z","status":"FINISHED","matchday":22,"homeTeamName":"Leicester City","awayTeamName":http://api.football-data.org/alpha/fixtures/136834"},"soccerseason":{"href":"http://api.football-data.org/alpha/soccerseasons/354"},"homeTeam":{"href":"http://api.football-data.org/alpha/teams/58"},"awayTeam":{"href":"http://api.football-data.org/alpha/teams/64"}},"date":"2015-01-17T15:00:00Z","status":"FINISHED","matchday":22,"homeTeamName":"阿斯顿维拉

作为一个起点,数据似乎是json,所以一个好的起点是使用json_decode,这样数据就可以在php中使用。

要在php中的数组中获取这些数据:

$json=json_decode( $data_from_api_call, true );

然后循环浏览数据:

foreach( $json as $key ){
    echo $key;
}

这应该会让你在获得想要的方面领先一步