javascript - 如何从 json 对象输出一些东西?

标签 javascript jquery json

我有以下 json:

   "responseData":{
      "results":[
         {
            "GsearchResultClass":"GimageSearch",
            "width":"600",
            "height":"530",
            "imageId":"ANd9GcRnCkl_5N-gAKDeyTvALVLqZJsTUP4M24qEL6MlBB3cOZo-yyAIAoNbJHkR",
            "tbWidth":"135",
            "tbHeight":"119",
            "unescapedUrl":"http://www.harlemfur.com/images/Dog_Olive.jpg",
            "url":"http://www.harlemfur.com/images/Dog_Olive.jpg",
            "visibleUrl":"www.harlemfur.com",
            "title":"\u003cb\u003eDogs\u003c/b\u003e Archives",
            "titleNoFormatting":"Dogs Archives",
            "originalContextUrl":"http://www.harlemfur.com/dogs/",
            "content":"This note below is from a \u003cb\u003edog\u003c/b\u003e",
            "contentNoFormatting":"This note below is from a dog",
            "tbUrl":"http://t0.gstatic.com/images?q\u003dtbn:ANd9GcRnCkl_5N-gAKDeyTvALVLqZJsTUP4M24qEL6MlBB3cOZo-yyAIAoNbJHkR"
         },
         {
            "GsearchResultClass":"GimageSearch",
            "width":"400",
            "height":"366",
            "imageId":"ANd9GcRde3tgTE21xhyW1CYlhQyrgvgd3ubj72GK7jl50GqXdC6QrGcVFXbD0w",
            "tbWidth":"124",
            "tbHeight":"113",
            "unescapedUrl":"http://static.howstuffworks.com/gif/dog-best-friend-1.jpg",
            "url":"http://static.howstuffworks.com/gif/dog-best-friend-1.jpg",
            "visibleUrl":"animals.howstuffworks.com",
            "title":"HowStuffWorks \u0026quot;Is a \u003cb\u003edog\u003c/b\u003e really a man\u0026#39;s best friend?\u0026quot;",
            "titleNoFormatting":"HowStuffWorks \u0026quot;Is a dog really a man\u0026#39;s best friend?\u0026quot;",
            "originalContextUrl":"http://animals.howstuffworks.com/pets/dog-best-friend.htm",
            "content":"See more \u003cb\u003edog\u003c/b\u003e images.",
            "contentNoFormatting":"See more dog images.",
            "tbUrl":"http://t3.gstatic.com/images?q\u003dtbn:ANd9GcRde3tgTE21xhyW1CYlhQyrgvgd3ubj72GK7jl50GqXdC6QrGcVFXbD0w"
         },
         {
            "GsearchResultClass":"GimageSearch",
            "width":"400",
            "height":"358",
            "imageId":"ANd9GcRq2Pn5YCq81h03V0Gv8mDrs00vFqQVFqdvMEFo3EIFuv7ILCq4wgoJwiA",
            "tbWidth":"124",
            "tbHeight":"111",
            "unescapedUrl":"http://www.mydogneeds.com/dog-groups/herding-dogs/german-shepherd-dog.jpg",
            "url":"http://www.mydogneeds.com/dog-groups/herding-dogs/german-shepherd-dog.jpg",
            "visibleUrl":"www.mydogneeds.com",
            "title":"German Shepherd, Herding \u003cb\u003eDog\u003c/b\u003e Breeds",
            "titleNoFormatting":"German Shepherd, Herding Dog Breeds",
            "originalContextUrl":"http://www.mydogneeds.com/dog-groups/dog-breed-german-shepherd-dog.html",
            "content":"Herding \u003cb\u003eDog\u003c/b\u003e Breeds - German",
            "contentNoFormatting":"Herding Dog Breeds - German",
            "tbUrl":"http://t1.gstatic.com/images?q\u003dtbn:ANd9GcRq2Pn5YCq81h03V0Gv8mDrs00vFqQVFqdvMEFo3EIFuv7ILCq4wgoJwiA"
         },
         {
            "GsearchResultClass":"GimageSearch",
            "width":"350",
            "height":"349",
            "imageId":"ANd9GcTUELr8ovAZ0E_4Gt9zYz3fsc5YG2VL7KOoWbx_hhzwnaLjcGPS0da_hVQ",
            "tbWidth":"120",
            "tbHeight":"120",
            "unescapedUrl":"http://www.costumedogs.com/wp-content/uploads/2007/07/tux.jpg",
            "url":"http://www.costumedogs.com/wp-content/uploads/2007/07/tux.jpg",
            "visibleUrl":"www.costumedogs.com",
            "title":"Poker Games Online",
            "titleNoFormatting":"Poker Games Online",
            "originalContextUrl":"http://www.costumedogs.com/",
            "content":"\u003cb\u003eDog\u003c/b\u003e",
            "contentNoFormatting":"Dog",
            "tbUrl":"http://t2.gstatic.com/images?q\u003dtbn:ANd9GcTUELr8ovAZ0E_4Gt9zYz3fsc5YG2VL7KOoWbx_hhzwnaLjcGPS0da_hVQ"
         }
      ],
      "cursor":{
         "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":"158000000",
         "currentPageIndex":0,
         "moreResultsUrl":"http://www.google.com/images?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den\u0026q\u003ddog"
      }
   },
   "responseDetails":null,
   "responseStatus":200

我如何遍历它以获取所有 4 个结果对象的 url

只是想了解如何从 json 中提取数据。

最佳答案

就像处理任何其他 JavaScript 对象一样。

var results = responseData.results;
var i;
for (i = 0; i < results.length; i++) {
    // Do something with results[i].url
}

关于javascript - 如何从 json 对象输出一些东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7297535/

相关文章:

javascript - 在 Jest 中,如何使测试失败?

javascript - DataTable 在 onClick 事件后丢失 fnCreatedCell

javascript - Bootstrap 工具提示不会在 <a> 标签点击时隐藏

javascript - 如何从异步调用返回响应?

jquery - 本地ajax调用成功但没有返回数据

python - 网页抓取 futbin.com

javascript - 如何为 NodeJS 中的自定义错误类获取正确的回溯?

javascript - 如何使用ajax显示JSON

json - 从 json 主体访问键的值

javascript - 使用 Phantom/Casper 进行基于浏览器的测试