Object.keys()获取子项数

时间:2014-06-04 02:53:38

标签: javascript json angularjs

我有以下数据源 - 使用X2JS转换为使用XML的JSON:

{
    "blog": {
        "article": [
            {
                "id": "1",
                "author": "eat-sleep-code",
                "title": {
                    "__cdata": "Thefirstarticle."
                },
                "content": {
                    "__cdata": "\nThisismyfirstarticleinmytestsite.\n"
                },
                "createdate": "2014-05-09"
            },
            {
                "id": "2",
                "author": "eat-sleep-code",
                "title": {
                    "__cdata": "Thesecondarticle."
                },
                "content": {
                    "__cdata": "\nThisismysecondarticleinmytestsite.Thisarticle'screatedateisactuallyearlier.\n"
                },
                "createdate": "2014-05-08"
            }
        ]
    }
}

我想找到"文章的数量"。

Object.keys(jsonObject).length;只是得到了我1.我猜是因为它找到了一个"博客"项目

1 个答案:

答案 0 :(得分:0)

jsonObject.blog.article.length