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

时间:2018-11-29 00:51:28

标签: json html5 rest api

我想通过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对象内部获取数据,然后从属性对象内部获取数据

1 个答案:

答案 0 :(得分:1)

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