REST API - 使用JQUERY将JSON数据转换为HTML表

问题描述 投票:1回答:1

我想通过Jquery将API中的数据显示到HTML表,但是它没有将数据显示在表中。我相信这是由于JSON结构这是HTML文件

        <thead>
            <tr>
                <th>A</th>
                <th>B</th>
                <th>C</th>
            </tr>
        </thead>
        <tbody id="mydata">
            <tr>
                <td>[[E]]</td>
                <td>[[F]]</td>
                <td>[[G]]</td>
            </tr>           
        </tbody>
    </table>
    </div>

    <script>
        function UserAction() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
         if (this.readyState == 4 && this.status == 200) {
             alert(this.responseText);
         }
    };
    xhttp.open("GET", "https:xxxxxxx", true);
    xhttp.setRequestHeader("Content-type", "application/json");
    xhttp.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1Nixxxxxxx");
}
    $("#mydata").mirandajs(xhhtp);
    </script>

关于JSON响应,我想获取播放器,时间戳和原因,并将数据呈现到表中(在示例E,F,G中)这里是API响应

{
    "meta": {
        "active": 2,
        "expired": 275,
        "total": 277
    },
    "links": {
        "next": "https://api.xxxxxxx"
    },
    "data": [
        {
            "type": "xxx",
            "id": "xxxx",
            "meta": {
                "player": "Serbo"
            },
            "attributes": {
                "id": "xxxx",
                "uid": "xxxx",
                "timestamp": "2018-07-11T13:02:14.663Z",
                "reason": "xxxxxxx",
                "note": null,
                "identifiers": [
                    {
                        "id": xxxxxxx,
                        "type": "xxxxxxx",
                        "identifier": "xxxxxxx",
                        "private": true,
                        "lastSeen": "2018-08-17T16:23:24.865+00:00"
                    }
                ]

请注意,我需要来自json对象内部的数据,然后是属性对象内的数据

json html5 rest api
1个回答
1
投票

解决了它,它是关于我调用API的方式

© www.soinside.com 2019 - 2024. All rights reserved.