【问题标题】:Creating an html table using api data使用 api 数据创建 html 表
【发布时间】:2015-02-22 13:37:15
【问题描述】:

我正在从 php 中的 api 源请求数据,我可以将数据显示在页面上。它的格式如下。我想把这些数据放在一个 html 表中以供用户阅读。例如,我想从这个数据中只向用户显示这部分“莱斯特城 0 斯托克城足球俱乐部 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": "莱斯特城","awayTeamName":"斯托克城FC","re​​sult":{"goalsHomeTeam":0,"goalsAwayTeam":1}},{"_links":{"self":{"href":" 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":"@987654330 @"}},"date":"2015-01-17T15:00:00Z","status":"FINISHED","matchday":22,"homeTeamName":"阿斯顿维拉

【问题讨论】:

    标签: php api


    【解决方案1】:

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

    要在 php 中的数组中获取此数据:

    $json=json_decode( $data_from_api_call, true );
    

    然后循环遍历数据:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 2020-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      相关资源
      最近更新 更多