Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery解析带有非法令牌的JSON数据_Jquery_Json_Google Analytics Api - Fatal编程技术网

使用jQuery解析带有非法令牌的JSON数据

使用jQuery解析带有非法令牌的JSON数据,jquery,json,google-analytics-api,Jquery,Json,Google Analytics Api,我正在尝试使用jQuery解析一些JSON数据,但在尝试“瞄准”某些条目时遇到了问题,因为某些JSON条目在获取时包含非法字符(如:)和jQuery错误,并显示消息“意外标记:” 这是我的jQuery脚本,其中第一个附件获取数据时没有任何错误('j.profileInfo.profileName'),第二行导致问题('j.totalsForAllResults.ga:visitors') var myjson='1〕{ “itemsPerPage”:50, "总成绩":1,, “profileI

我正在尝试使用jQuery解析一些JSON数据,但在尝试“瞄准”某些条目时遇到了问题,因为某些JSON条目在获取时包含非法字符(如:)和jQuery错误,并显示消息“意外标记:”

这是我的jQuery脚本,其中第一个附件获取数据时没有任何错误('j.profileInfo.profileName'),第二行导致问题('j.totalsForAllResults.ga:visitors')

var myjson='1〕{
“itemsPerPage”:50,
"总成绩":1,,
“profileInfo”:{
“profileId”:“12345678”
},
“总体结果”:{
“ga:访客”:“100”,
“ga:新访问”:“30”
}
}';
var j=$.parseJSON(myjson);
$(“body”).append(“+j.profileInfo.profileName+”);
$(“body”).append(“”+j.totalsForAllResults.ga:visitors+”

”);
我正在从GoogleAPI获取json数据,因此很遗憾,我无法编辑json。是否有其他方法可以将数据作为目标,也许是j.totalsForAllResults[0]中的一长行,这样我就不需要输入:了?有人知道这个问题的解决方案吗?

在这种情况下使用,而不是


演示:

可能会有所帮助。是的!谢谢,太好了。
var myjson = '{
    "itemsPerPage": 50,
    "totalResults": 1,
    "profileInfo": {
        "profileId": "12345678"
    },
    "totalsForAllResults": {
        "ga:visitors": "100",
        "ga:newVisits": "30"
    }
}';

var j = $.parseJSON(myjson);

$("body").append("<h2>" + j.profileInfo.profileName + "</h2>");
$("body").append("<p>" + j.totalsForAllResults.ga:visitors + "</p>");
j.totalsForAllResults['ga:visitors']