有效json的jQuery语法错误 [英] jQuery syntax error for a valid json

查看:119
本文介绍了有效json的jQuery语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用可从URL找到的jQuery ajax获取instagram用户详细信息

I am trying to get the instagram user details using jQuery ajax which can be found from the url

https://www.instagram.com/instagram/?__a=1

但是当我通过以下代码通过ajax调用相同的代码

But when i call the same through ajax from my following code

$(document).ready(function(){
 var instagram = 'instagram';
    $.ajax({
      url : 'https://www.instagram.com/'+ instagram +'/?__a=1',
      dataType: "jsonp",
      success: function(e) {
        document.write(JSON.stringify(e));
      }
    });
});

它返回一个错误:

缺失;在声明之前[在Json中]

missing ; before statement [In Json]

但是,当我将其复制并粘贴到一些可用的在线工具上进行验证时,它会显示有效格式的json.

However when i copy and paste it for validation on some online tools available it is showing valid formatted json.

DEMO: https://codepen.io/abhibagul/pen/WXGoYb?editors = 0010

错误在浏览器控制台中可见.

Error is visible in the browser console.

推荐答案

如果您以JSON的身份被重新使用, 从dataType: "jsonp"更改为dataType: "json"

If you are getting respone as JSON, Change from dataType: "jsonp" to dataType: "json"

有效的json响应看起来像

Valide json response would look like

{
     "Name": "Foo",
     "Id": 192.168.73.96,
     "Rank": 7
}

而jsonp就像

parseResponse({"Name": "Foo", "Id": 1234, "Rank": 7});

此处

这篇关于有效json的jQuery语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆