代码吐出NaN 7次

时间:2016-09-15 17:29:43

标签: javascript

我不明白为什么我会得到NaN。是否有我遗失的东西,可能是对象,还是我的代码?



$(document).ready(function() {

  var text = {
    "kind": "books#volume",
    "id": "Wfan6L9RGgYC",
    "etag": "UlsLzySUlh0",
    "selfLink": "https://www.googleapis.com/books/v1/volumes/Wfan6L9RGgYC",
    "volumeInfo": {
      "title": "The Modern Web",
      "subtitle": "Multi-device Web Development with HTML5, CSS3, and JavaScript",
      "": [
        "Peter Gasston"
      ],
      "publisher": "No Starch Press",
      "publishedDate": "2013",
      "description": "<p><b>A Guide to Modern Web Development</b><br></p><p>Today's web technologies are evolving at near-light speed, bringing the promise of a seamless Internet ever closer to reality. When users can browse the Web on a three-inch phone screen as easily as on a fifty-inch HDTV, what's a developer to do?</p><p>Peter Gasston's <i>The Modern Web</i> will guide you through the latest and most important tools of device-agnostic web development, including HTML5, CSS3, and JavaScript. His plain-English explanations and practical examples emphasize the techniques, principles, and practices that you'll need to easily transcend individual browser quirks and stay relevant as these technologies are updated.</p><p>Learn how to:</p><p>* Plan your content so that it displays fluidly across multiple devices<br>* Design websites to interact with devices using the most up-to-date APIs, including Geolocation, Orientation, and Web Storage<br>* Incorporate cross-platform audio and video without using troublesome plug-ins<br>* Make images and graphics scalable on high-resolution devices with SVGUse powerful HTML5 elements to design better forms</p><p>Turn outdated websites into flexible, user-friendly ones that take full advantage of the unique capabilities of any device or browser. With the help of <i>The Modern Web</i>, you'll be ready to navigate the front lines of device-independent development.</p>",
      "industryIdentifiers": [{
        "type": "ISBN_10",
        "identifier": "1593274874"
      }, {
        "type": "ISBN_13",
        "identifier": "9781593274870"
      }],
      "readingModes": {
        "text": true,
        "image": true
      },
      "pageCount": 264,
      "printedPageCount": 266,
      "dimensions": {
        "height": "24.00 cm",
        "width": "17.80 cm",
        "thickness": "1.50 cm"
      },
      "printType": "BOOK",
      "categories": [
        "Computers / Software Development & Engineering / General",
        "Computers / Web / Design"
      ],
      "averageRating": 4.5,
      "ratingsCount": 3,
      "maturityRating": "NOT_MATURE",
      "allowAnonLogging": true,
      "contentVersion": "1.2.2.0.preview.3",
      "imageLinks": {
        "smallThumbnail": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=5&edge=curl&imgtk=AFLRE72KO7jCxe5uWt_wdrgHfdSNO_raoAKYbPNaAILa300r3DxeVHIqEeZto77JClWzw41ZwwbcMlVl2Ki9dF_ycIEUDhwbetDSF6K112O_XoebMDRoRNA5vskWyCtpGig-LaVPbE7j&source=gbs_api",
        "thumbnail": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=1&edge=curl&imgtk=AFLRE70to3PUyJeiv-brcBCzs330NDwRGM4cYu9gHzdVNLrIEn7ghBo5Gms9MAFxQ8ZkRt0-JZhCJq7T0V_vOLwMhDu4f_2icMtDrO5bMPSqRa4EuB9-3XGaNH-UxsYBvJIMUadwdd4Y&source=gbs_api",
        "small": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=2&edge=curl&imgtk=AFLRE709uVhXoOlgZxdwB4DKF0X1zVPvV7_4EA_PvhNlIGLKknTSsZiIoDnsJPsswWKBQIoSC-gJ0vOe_4kTiWPU38xZydOliDp5u0SxJqqFbDIKnz-KxprkLg7Ze2fxJWGBXRQSgHJA&source=gbs_api",
        "medium": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=3&edge=curl&imgtk=AFLRE72idQ0vc5gY408WHZTWFY8AOQLhGVbI4ktB4O6NXQFbbHY0VrM0PJWA_XF_98_NThQtP8tvw73qpSwqkGoi-QKzMPfi_M75VzK-zbxVsFZ_rtfeMGHWREhGACvV-F39BhQ1WXwt&source=gbs_api",
        "large": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=4&edge=curl&imgtk=AFLRE73M-PJZ0bTkffdLAwU427ppNpxsenoBSi91ABnrm4lNMPwOBNDIL23OTK7ZNvGlGChk9klXAP3DDoQbLXPwct-F_m9j1KKJ4w77HkeP69-eYdwxW1Z5iNgVYqyZCRj3AkAHmOaZ&source=gbs_api",
        "extraLarge": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=6&edge=curl&imgtk=AFLRE70yPdCZ5tbR5aL9WbnodE4Uf263MR_bPekV6tab5QKe193uKXqXqilaTmc-bByqZGmaEk38KBic64e-dp8VON30C-E7eJP-TR-6cjVA3dmVTARYkMGMiE5dQsPsMGO2z_6p4ryx&source=gbs_api"
      },
      "language": "en",
      "previewLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&source=gbs_api",
      "infoLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&source=gbs_api",
      "canonicalVolumeLink": "http://books.google.com/books/about/The_Modern_Web.html?hl=&id=Wfan6L9RGgYC"
    },
    "layerInfo": {
      "layers": [{
        "layerId": "geo",
        "volumeAnnotationsVersion": "8"
      }]
    },
    "saleInfo": {
      "country": "US",
      "saleability": "FOR_SALE",
      "isEbook": true,
      "listPrice": {
        "amount": 27.95,
        "currencyCode": "USD"
      },
      "retailPrice": {
        "amount": 15.37,
        "currencyCode": "USD"
      },
      "buyLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&buy=&source=gbs_api",
      "offers": [{
        "finskyOfferType": 1,
        "listPrice": {
          "amountInMicros": 27950000,
          "currencyCode": "USD"
        },
        "retailPrice": {
          "amountInMicros": 15370000,
          "currencyCode": "USD"
        },
        "giftable": true
      }]
    },
    "accessInfo": {
      "country": "US",
      "viewability": "PARTIAL",
      "embeddable": true,
      "publicDomain": false,
      "textToSpeechPermission": "ALLOWED",
      "epub": {
        "isAvailable": true
      },
      "pdf": {
        "isAvailable": true
      },
      "webReaderLink": "http://books.google.com/books/reader?id=Wfan6L9RGgYC&hl=&printsec=frontcover&output=reader&source=gbs_api",
      "accessViewStatus": "SAMPLE",
      "quoteSharingAllowed": false
    }
  }

  $.each(text, function(i, value) {
    $('</p>').appendTo("#container").text(text[i].title + text[i].subtitle);
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">

</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

$ .each函数循环遍历对象根目录下的每个属性,以及对象的结构方式,并非每个属性都有嵌套的标题字幕财产。

您要么必须一致地构建对象,要么在尝试访问它们之前检查所需的属性。