Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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
Javascript AngularJS或JQuery解析错误格式JSON(http get)_Javascript_Jquery_Ajax_Json_Angularjs - Fatal编程技术网

Javascript AngularJS或JQuery解析错误格式JSON(http get)

Javascript AngularJS或JQuery解析错误格式JSON(http get),javascript,jquery,ajax,json,angularjs,Javascript,Jquery,Ajax,Json,Angularjs,我试图从远程服务器解析错误的json格式,如下所示: //[ {},{} ] 我的AngularJS代码: $http.get('http://www.example.com/badjson') .success(function(data) { console.log(data); }); 但我在JSON数据的第1行第1列得到了错误:JSON.parse:意外字符。 我也无法使用$.getJSON在Jquery中运行它。有什么想法吗?您需要使用transformR

我试图从远程服务器解析错误的json格式,如下所示:

//[
{},{} 
]
我的AngularJS代码:

$http.get('http://www.example.com/badjson')
    .success(function(data) {
        console.log(data);
});
但我在JSON数据的第1行第1列得到了错误:JSON.parse:意外字符。
我也无法使用$.getJSON在Jquery中运行它。有什么想法吗?

您需要使用
transformResponse
功能获取原始响应:

$http.get('http://www.example.com/badjson', { 
    transformResponse: function(d, h) { 
        return d; 
    }
})
.success(function(data) {
    conole.log(data);
});

您需要使用
transformResponse
函数获取原始响应:

$http.get('http://www.example.com/badjson', { 
    transformResponse: function(d, h) { 
        return d; 
    }
})
.success(function(data) {
    conole.log(data);
});

您需要使用
transformResponse
函数获取原始响应:

$http.get('http://www.example.com/badjson', { 
    transformResponse: function(d, h) { 
        return d; 
    }
})
.success(function(data) {
    conole.log(data);
});

您需要使用
transformResponse
函数获取原始响应:

$http.get('http://www.example.com/badjson', { 
    transformResponse: function(d, h) { 
        return d; 
    }
})
.success(function(data) {
    conole.log(data);
});