从JSON API响应中返回元数据值

时间:2017-04-04 13:41:09

标签: json ajax

我有一个api请求,返回JSON数据,然后用于填充html表。我可以使用item.name填充表格...我想为player.field添加元数据值,但我无法访问它。这是JSON响应:

{
"list": [
    {
        "id": 55,
        "name": "0046GS (RMS03241708)",
        "description": "S 12-7 M-S 10-9",
        "uuid": "6f4b5bfd-6d17-4095-9e48-7b9313f7f8c6",
        "previewPlayer": false,
        "enabled": true,
        "mac": "00-00-00-00-00-00",
        "type": "CHROMEBOX",
        "distributionServer": {
            "id": 2,
            "name": "Main",
            "driver": "IP_P2P"
        },
        "playergroups": [
            {
                "id": 2,
                "name": "GameStop",
                "numberOfPlayers": 454
            }
        ],
        "playerDisplays": [
            {
                "id": 55,
                "name": "Display 1",
                "channel": {
                    "id": 53,
                    "name": "GameStop TV"
                },
                "screenCounter": 1
            }
        ],
        "requestLogs": false,
        "downloadThreads": 1,
        "unusedFilesCache": 24,
        "planDeliveryMethod": "CONTENT_MANAGER_DIRECT",
        "pollingInterval": 1,
        "pollingUnit": "MINUTES",
        "logLevel": "normal",
        "metadataValue": [
            {
                "id": 12512,
                "value": "true",
                "playerMetadata": {
                    "id": 34,
                    "name": "Player.field",
                    "datatype": "BOOLEAN",
                    "valueType": "ANY",
                    "order": 4
                }
            },
            {
                "id": 1085,
                "value": "77056",
                "playerMetadata": {
                    "id": 31,
                    "name": "Player.ZipCode",
                    "datatype": "STRING",
                    "valueType": "ANY",
                    "order": 30
                }
            },

            {
                "id": 1071,
                "value": "22:15",
                "playerMetadata": {
                    "id": 10,
                    "name": "Player.ScreenOff_Wednesday",
                    "datatype": "STRING",
                    "valueType": "ANY",
                    "order": 12
                }
            }
        ],
        "usedPairingKey": "HBVULW",
        "active": "ACTIVE",
        "lastModified": "2017-04-03 20:12:43",
        "timezoneOffset": "0"
    }
],
"offset": 0,
"count": 68
}

这是ajax请求:

$.ajax({
type: 'GET',
url: "https://sampleserver.com:8080/ContentManager/api/rest/players?limit=1&offset=0&sort=name&filters=%7BplayerStatus%20:%20%7Bvalues:%5B'ACTIVE'%5D,%20comparator%20:%20'eq'%7D%7D",
dataType: "json",
success: function(data) {
   $.each(data.list, function(i, item) {
    var tr = $('<tr><td>'+item.name+'</td><td>'+some.JSONResponse+'</td></tr>').appendTo('#scalaapi');
});
}
});

我被困在如何专门显示player.field的值...&#34;值&#34;:&#34; true&#34;,

感觉它应该很简单,但我的尝试都是未定义的。

如果声明......

success: function(data) {
   $.each(data.list, function(i, item) {
    var tr = $('<tr><td>'+item.name+'</td><td class="val">...</td></tr>').appendTo('#scalaapi');
    var bool = function(i,item) {if (item.metadataValue.id = '12512');
    tr.find('.val').text(bool);};
        });
    }
});

0 个答案:

没有答案