如何计算jQuery $ .ajax结果中的响应数?

iam*_*ick 0 ajax jquery json

我正在尝试计算$ .ajax调用中的结果数.

    $.ajax({
        'async': true,
        'crossDomain': true,
        'url': 'XXX',
        'method': 'GET',
        'headers': {
            'key': 'XXX',
            'scope': 'XXX',
            'content-type': 'application/json',
            'cache-control': 'no-cache'
        },
        'processData': false,
        'data': {},
        error: function(jqXHR, textStatus, errorThrown) {
            // Default error
            log('error');

        },
        success: function(data, textStatus, jqXHR) {
            log('success');
            log(data);
            var ArrayContent = data.length;
            log(ArrayContent)

        }
    }).done(function(response) {
        log('done');
    });
Run Code Online (Sandbox Code Playgroud)

我的jSon回复是 Object {3858: Object, 4667: Object, 4668: Object, 4680: Object, 4710: Object}3858: Object4667: Object4668: Object4680: Object4710: Object__proto__: Object

我已经尝试了在这个网站上找到的几个解决方案,但我不能让它们中的任何一个工作.

任何有关解决方案的建议都将非常感谢.

-C

Aju*_*ohn 5

您可以使用以下代码在对象中找到自己的可枚举属性的数量:

Object.keys(response).length;
Run Code Online (Sandbox Code Playgroud)