从javascript(调用API)返回错误的json,包括对象(_proto__)

从javascript(调用API)返回错误的json,包括对象(_proto__),javascript,jquery,json,Javascript,Jquery,Json,我从javascript调用api,该api返回json。使用以下代码调用json: document.ready(function(){ $.getJSON(url, function (data) { console.log(data); $("#test").text(data); }); } }); <p id="test"></p>

我从javascript调用api,该api返回json。使用以下代码调用json:

document.ready(function(){
$.getJSON(url,
            function (data) {
               console.log(data);
               $("#test").text(data);
            });
        }
}); 

<p id="test"></p>
但我的有效json如下所示:

{
  "author": "Hay House UK",
  "title": "Top 15 Must-Read Books For 2014",
  "text": "When a year ends, it’s like finishing a favorite book. You really don’t want it to end because you’re still savoring all the good parts, but you also want to wrap it up so you can start the next one.\nBefore we close this chapter on 2013, we’d like to share some of oy and You Can Heal Your Life (YCHYL), both of which became bestsellers and established Louise as a leader in the New Age movement. To date, YCHYL has sold more than 16 million copies worldwide and has been published in 25 languages. Today, Hay House is committed to publishing products that have a positive self-help slant conducive to healing planet Earth.",
  "images": [
    {
      "primary": "true",
      "caption": "Hay House",
      "url": "http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg"
    },
    {
      "caption": "top books for 2014 hay house",
      "url": "http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg"
    }
  ],
  "date_created": "Wed, 01 Jan 2014 09:17:31 PST",
  "categories": {
    "entertainment_culture": 0.09647619047619045,
    "hospitality_recreation": 0.04541137315797972,
    "other": 0,
    "business_finance": 0.039999999999999994,
    "technology_internet": 0.014511842376414444,
    "socialissues": 0.07857142857142856,
    "sports": 0.05831770720339089,
    "humaninterest": 0.04666666666666667,
    "religion_belief": 0.03994037416667575,
    "war_conflict": 0.053333333333333316,
    "education": 0.13887284818770693,
    "health_medical_pharma": 0.09809523809523808,
    "labor": 0.048559733653411985,
    "law_crime": 0.01257142857142857,
    "politics": 0.12309533849221464,
    "environment": 0.08025982988254671,
    "weather": 0.013888095736801704,
    "disaster_accident": 0.011428571428571427
  },
  "html": "<div><div class=\"image_frame\"><img alt=\"Hay House\" src=\"http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg\"></img><div class=\"caption\">Hay House</div></div><div class=\"image_frame\"><img alt=\"top books for 2014 hay house\" height=\"215\" src=\"http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg\" width=\"374\"></img><div class=\"caption\">top books for 2014 hay house</div></div><p>When a year ends, it&rsquo;s like finishing a favorite book. You really don&rsquo;t want it to end because you&rsquo;re still saank\">Mife. But she went one step further and collected scientific evidence to support wha together to meet the challenges and opportunities in the days ahead. And for our future leaders&mdash;GenYers (everyone else!), there are tips for you, too!</p><p>6. <a href=\"http://www.hayhouse.com/details.php?id=8326\" target=\"_blank\">Love Your Enemies</a>  learn how to identify the people who challenge you (even yourself!) and learn to transform your relationships with them.</p><p>7.&nbsp;<a href=\"http://www.hayhouse.com/details.php?id=9229\" target=\"_blank\">Forgiveness</a>(Iyanla Vanzant): Iyanla says that forgiveness will cure anything that ails you, and she has created a powerful program to help you to forgive evlishing products that have a positive self-help slant conducive to healing planet Earth.</p></div>",
  "supertags": [
    {
      "id": 18957,
      "positions": [
        [
          873,
          881
        ],
        [
          1093,
          1100
        ]
      ],
      "name": "Medicine",
      "score": 0.9,
      "contentMatch": 0.945054945054945,
      "categories": {
        "692348": "Medicine",
        "14500038": "Health Sciences"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.2922374429223744,
      "depth": 0.7647058823529411
    },
    {
      "id": 201657,
      "positions": [
        [
          1592,
          1611
        ]
      ],
      "name": "Scientific evidence",
      "score": 0.8,
      "contentMatch": 0.2527472527472527,
      "categories": {
        "700292": "Scientific method",
        "13167332": "Sources of knowledge",
        "37407028": "Evidence"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.817351598173516,
      "depth": 0.7058823529411764
    },
    {
      "id": 23315,
      "positions": [
        [
          982,
          988
        ],
        [
          1093,
          1107
        ],
        [
          1101,
          1107
        ],
        [
          1474,
          1477
        ],
        [
          1474,
          1476
        ]
      ],
      "name": "Physician",
      "score": 0.6,
      "contentMatch": 0.802197802197802,
      "categories": {
        "718247": "Physicians",
        "787658": "Occupations",
        "1006080": "Healthcare occupations"
      },
      "type": 1,
      "senseRank": 1,
      "variety": 0.3105022831050228,
      "depth": 0.7058823529411764
    }
  ],
  "type": "article",
  "date": "Wed, 1 Jan 2014 08:00:00 GMT",
  "cid": 1235024564,
  "url": "http://www.healyourlife.com/author-hay-house/2014/01/wisdom/personal-growth/the-top-15-must-read-books-for-2014"
}
{
“作者”:“Hay House UK”,
“标题”:“2014年15大必读书籍”,
“文本”:“当一年结束时,这就像完成一本喜爱的书。你真的不希望它结束,因为你仍然在品味所有美好的部分,但你也希望结束它,这样你就可以开始下一个。\n在2013年结束本章之前,我们想分享一些oy,你可以治愈你的生活(YCHYL),这两本书都成为畅销书,并确立了路易丝在新时代运动中的领导地位。迄今为止,YCHYL已在全球售出1600多万册,并以25种语言出版。如今,Hay House致力于出版具有积极自助倾向的产品,有助于治愈地球。”,
“图像”:[
{
“primary”:“true”,
“说明”:“干草屋”,
“url”:”http://www.healyourlife.com/img/resize_cache/1067-hay_house_logo_keep_aspect_215x215.jpg"
},
{
“说明”:“2014年hay house畅销书”,
“url”:”http://www.healyourlife.com/img/resize_cache/3667-Top_15_Must_Read_Books_For_2014_keep_aspect_374x215.jpg"
}
],
“创建日期”:“2014年1月1日星期三太平洋标准时间09:17:31”,
“类别”:{
“娱乐文化”:0.09647619047619045,
“酒店娱乐”:0.04541137315797972,
“其他”:0,
“商业金融”:0.039999994,
“互联网技术”:0.0145118423764444,
“社会问题”:0.07857142857142856,
“体育”:0.05831770720339089,
“人文利益”:0.04667,
“宗教信仰”:0.03994037416667575,
“战争与冲突”:0.0533316,
“教育”:0.13887284848770693,
“健康医疗制药”:0.09809523809523808,
“劳工”:0.048559733653411985,
“法律与犯罪”:0.01257142857142857,
“政治”:0.12309533849221464,
“环境”:0.08025982988254671,
“天气”:0.01388809573681704,
“灾难事故”:0.011428571428571427
},
“html:“2014年Hay house的Hay house Top书籍”Hay house当一年结束时,就像完成了一本喜爱的书。你真的不希望它结束,因为你仍然是saank“>米菲。但她更进一步,收集了科学证据,共同支持世界卫生大会,迎接未来的挑战和机遇。对于我们未来的领导者&mdash;GenYers(其他人!),也有一些小贴士给你!

6.学习如何识别挑战你的人(甚至你自己!)并学会改变你与他们的关系。

7.(Iyanla Vanzant):Iyanla说宽恕可以治愈任何让你不舒服的事情,她创建了一个强大的计划,帮助你宽恕那些有助于治愈地球的积极自助倾向的产品。

“, “超级标签”:[ { “id”:18957, “职位”:[ [ 873, 881 ], [ 1093, 1100 ] ], “名称”:“药物”, “得分”:0.9分, “内容匹配”:0.9450549445054945, “类别”:{ “692348”:“医学”, “14500038”:“健康科学” }, “类型”:1, “senseRank”:1, “品种”:0.2922374429223744, “深度”:0.7647058823529411 }, { “id”:201657, “职位”:[ [ 1592, 1611 ] ], “名称”:“科学证据”, “得分”:0.8分, “内容匹配”:0.2527472527, “类别”:{ “700292”:“科学方法”, “13167332”:“知识来源”, “37407028”:“证据” }, “类型”:1, “senseRank”:1, “品种”:0.817351598173516, “深度”:0.7058823529411764 }, { “id”:23315, “职位”:[ [ 982, 988 ], [ 1093, 1107 ], [ 1101, 1107 ], [ 1474, 1477 ], [ 1474, 1476 ] ], “姓名”:“医生”, “得分”:0.6分, “内容匹配”:0.802197802197802, “类别”:{ “718247”:“医生”, “787658”:“职业”, “1006080”:“医疗保健职业” }, “类型”:1, “senseRank”:1, “品种”:0.310502283100228, “深度”:0.7058823529411764 } ], “类型”:“文章”, “日期”:“2014年1月1日星期三08:00:00 GMT”, “cid”:1235024564, “url”:”http://www.healyourlife.com/author-hay-house/2014/01/wisdom/personal-growth/the-top-15-must-read-books-for-2014" }

我需要纯json,只想从javascript在页面上显示json,不包括proto和所有其他属性。

查看文档:

它说:

成功回调传递返回的数据,该数据通常是 JSON结构定义并解析的JavaScript对象或数组 使用$.parseJSON()方法。它还传递 回应

这意味着生成的JSON字符串将自动解析为JavaScript对象

如果希望结果为JSON格式,可以对结果使用
JSON.stringify()

function (data) {
    jsonData = JSON.stringify(data);
    console.log(jsonData);
    $("#test").text(jsonData);
});
但是,现在您不需要解析和字符串化JSON值。如果您只是对字符串表示感兴趣,您可以执行以下操作:

$.ajax({
    dataType: "text",
    url: url,
    success: function (data) {
        console.log(data);
        $("#test").text(data);
    }
});
请记住,
$.getJSON
只是以下内容的快捷方式:

$.ajax({
    dataType: "json",
    url: url,
    data: data,
    success: success
});

因此,通过指定
数据类型:“json”
,您告诉jQuery,您需要一个json格式的字符串,然后该字符串将被自动解析。如果您指定
数据类型:“text”
,您应该只获得文本表示。

协议有什么问题吗?请正确缩进记录的对象好吗
$.ajax({
    dataType: "json",
    url: url,
    data: data,
    success: success
});