0

你好,也许是愚蠢的问题,但我如何打印例如这个开始

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'])

谢谢

4

1 回答 1

0

Paste this text json object in chrome's console. And try accessing text variable. It will auto complete and help you find the path to the objects inside the variable, you desire. That's what I do to json objects. For your start variable try this code.

var pages = text.responseData.cursor.pages;
for(var i=0; i < pages.length; i++){
   console.log(pages[i].start)
}  
于 2013-10-03T08:56:38.320 回答