在对象中打印对象

时间:2013-10-03 08:26:30

标签: javascript object

你好也许是个愚蠢的问题,但我怎样才能打印 start 这个

var text = {
"responseData": {
    "results": [
        {
            "GsearchResultClass": "GwebSearch",
            "unescapedUrl": "http://dojotoolkit.org/",
            "url": "http://dojotoolkit.org/",
            "visibleUrl": "dojotoolkit.org",
            "cacheUrl": "http://www.google.com/search?q=cache:sUiWYphwkaoJ:dojotoolkit.org",
            "title": "Unbeatable JavaScript Tools - The <b>Dojo Toolkit</b>",
            "titleNoFormatting": "Unbeatable JavaScript Tools - The Dojo Toolkit",
            "content": "<b>Dojo</b> saves you time, delivers powerful performance, and scales with your   development process. It&#39;s the <b>toolkit</b> experienced developers turn to for building <b>...</b>"
        },
        {
            "GsearchResultClass": "GwebSearch",
            "unescapedUrl": "http://dojotoolkit.org/download/",
            "url": "http://dojotoolkit.org/download/",
            "visibleUrl": "dojotoolkit.org",
            "cacheUrl": "http://www.google.com/search?q=cache:cQhx_NOJhyYJ:dojotoolkit.org",
            "title": "Download - The <b>Dojo Toolkit</b>",
            "titleNoFormatting": "Download - The Dojo Toolkit",
            "content": "This download is ideal for situations   where a custom build will not be   required."
        },
        {
            "GsearchResultClass": "GwebSearch",
            "unescapedUrl": "http://dojotoolkit.org/documentation/",
            "url": "http://dojotoolkit.org/documentation/",
            "visibleUrl": "dojotoolkit.org",
            "cacheUrl": "http://www.google.com/search?q=cache:ws95YbyVgxgJ:dojotoolkit.org",
            "title": "Documentation - The <b>Dojo Toolkit</b>",
            "titleNoFormatting": "Documentation - The Dojo Toolkit",
            "content": "How do I start learning Dojo? Where are   the docs? How do I get support and <b>...</b>"
        },
        {
            "GsearchResultClass": "GwebSearch",
            "unescapedUrl": "http://en.wikipedia.org/wiki/Dojo_Toolkit",
            "url": "http://en.wikipedia.org/wiki/Dojo_Toolkit",
            "visibleUrl": "en.wikipedia.org",
            "cacheUrl": "http://www.google.com/search?q=cache:6gxw4t2myDIJ:en.wikipedia.org",
            "title": "<b>Dojo Toolkit</b> - Wikipedia, the free encyclopedia",
            "titleNoFormatting": "Dojo Toolkit - Wikipedia, the free encyclopedia",
            "content": "<b>Dojo Toolkit</b> (stylized as dōjō toolkit) is an open source modular JavaScript library   (or more specifically JavaScript toolkit) designed to ease the rapid <b>...</b>"
        }
    ],
    "cursor": {
        "resultCount": "83,500",
        "pages": [
            {
                "start": "0",
                "label": 1
            },
            {
                "start": "4",
                "label": 2
            },
            {
                "start": "8",
                "label": 3
            },
            {
                "start": "12",
                "label": 4
            },
            {
                "start": "16",
                "label": 5
            },
            {
                "start": "20",
                "label": 6
            },
            {
                "start": "24",
                "label": 7
            },
            {
                "start": "28",
                "label": 8
            }
        ],
        "estimatedResultCount": "83500",
        "currentPageIndex": 0,
        "moreResultsUrl": "http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=dojo+toolkit",
        "searchResultTime": "0.20"
    }
},
"responseDetails": null,
"responseStatus": 200

}

我在访问对象中的对象时遇到问题。你能告诉我一些信息吗?

我想做类似的事情:

 alert(text.responseData['results'])

谢谢

1 个答案:

答案 0 :(得分:0)

将此text json对象粘贴到chrome的控制台中。并尝试访问text变量。它会自动完成并帮助您找到变量内部对象的路径。这就是我对json对象所做的。对于start变量,请尝试使用此代码。

var pages = text.responseData.cursor.pages;
for(var i=0; i < pages.length; i++){
   console.log(pages[i].start)
}  
相关问题