doujingxi3356 2017-03-14 21:53
浏览 57
已采纳

将JSON Array的数据输出为HTML

I'm trying to create an overlay for my twitch stream, which display not only the recent follower but a certain amount of them in chronological order.

Here a visual representation:

latest follower bottom

(Styling is done with HTML/CSS)

I've already managed to get the JSON but I don't know how to echo the names for each ['follows']['user']['display_name']

This is the API: https://api.twitch.tv/kraken/channels/kazutode/follows?limit=5&offset=0&client_id=nht9j8w0u4xazpm1fdc2fmkrqvoici

Here's my code so far (It's not alot, basically nothing xD)

<?php

$clientID = "nht9j8w0u4xazpm1fdc2fmkrqvoici";
$channel = "kazutode";
$limit = 5;
$offset = 0;

$response = json_decode(file_get_contents('https://api.twitch.tv/kraken/channels/'.$channel.'/follows?limit='.$limit.'&offset='.$offset.'&client_id='.$clientID), true);

?>

I know, I know. I should use curl but I don't know how so I stick to json_decode.

Can someone teach me how to get the wanted data out of the ['follows'] array?

  • 写回答

1条回答 默认 最新

  • dongxi1965 2017-03-14 21:59
    关注

    You need a foreach loop. Here is some PHP+HTML mixed to give you an idea:

    $table = '';
    $table .= '<table>';
    foreach($response['follows'] as $entry) {
        $table .= '<tr>';
        $table .= '<td>'.$entry['created_at'].'</td>';
        $table .= '<td>'.$entry['user']['display_name'].'</td>';
        $table .= '<td><a class="your-custom-class" href="'.$entry['_links']['self'].'">View channel</a></td>';
        $table .= '</tr>';
    }
    $table .= '</table>';
    
    echo $table;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)