AngularJS defaultHttpResponseTransform
试图找出数据是否为json并尝试解析它:
function defaultHttpResponseTransform(data, headers) {
if (isString(data)) {
// Strip json vulnerability protection prefix and trim whitespace
var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();
if (tempData) {
var contentType = headers('Content-Type');
if ((contentType && (contentType.indexOf(APPLICATION_JSON) === 0)) || isJsonLike(tempData)) {
data = fromJson(tempData);
}
}
}
return data;
}
然而,text/plain
中的回复数据是swift
消息,看起来像JSON
,但事实并非如此。当Angular尝试JSON.parse
时,我收到错误:
SyntaxError:意外的数字 at Object.parse(native) 在fromJson(http://localhost:8080/WebEastGui/build/js/app-vendor.js:41198:14)
有没有办法强制Angular不强制解析像字符串一样的JSON?