首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jsonify烧瓶解析错误

jsonify烧瓶解析错误
EN

Stack Overflow用户
提问于 2016-03-25 18:01:52
回答 2查看 324关注 0票数 0

简单地说,ajax收到来自烧瓶的jsonify响应,我找不到在html中呈现它的方法。我试过:

代码语言:javascript
复制
success: function(json) {
    $.each(json, function(index, element) {
        $('#main').append(element.title);
    });
}

印上了“不明”字。

然后我试着:

代码语言:javascript
复制
 $('#main').append(json[index].name)

但什么都没有印出来

下面是api返回的json:

代码语言:javascript
复制
{
  "albums": [
    {
      "artist_id": 19,
      "composer_id": 3,
      "id": 6,
      "img": "The_Fine_Art_of_Self_Destruction.jpg",
      "release_date": 2002,
      "title": "the fine art of self destruction"
    },
    {
      "artist_id": 26,
      "composer_id": 6,
      "id": 22,
      "img": "The_Blasters_%28album%29.jpg",
      "release_date": 1981,
      "title": "the blasters"
    },
    {
      "artist_id": 25,
      "composer_id": 6,
      "id": 25,
      "img": "XMoreFunInTheNewWorld.jpg",
      "release_date": 1983,
      "title": "more fun in the new world"
    },
    {
      "artist_id": 27,
      "composer_id": 8,
      "id": 28,
      "img": "220px-The_Angels_of_Light_Sing_%27Other_People%27.jpeg",
      "release_date": 2005,
      "title": "the angels of light sing 'other people'"
    },
    {
      "artist_id": 10,
      "composer_id": 10,
      "id": 32,
      "img": null,
      "release_date": 2008,
      "title": "when the flood comes"
    },
    {
      "artist_id": 31,
      "composer_id": 15,
      "id": 40,
      "img": "The_Willies.jpg",
      "release_date": 2002,
      "title": "the willies"
    }
  ]
}

我查看了许多东西,比如jQuery.parseJSON()和其他东西,但是都没有用。

谢谢你的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-25 18:03:29

代码语言:javascript
复制
 $.each(json, function(index, element) {

应该是

代码语言:javascript
复制
 $.each(json.albums, function(index, element) {
票数 0
EN

Stack Overflow用户

发布于 2016-03-25 18:03:07

将代码更新为

代码语言:javascript
复制
$.each(json.albums, function(index, element) {
        $('#main').append(element.title);
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36225317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档