【发布时间】:2015-06-12 22:52:03
【问题描述】:
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 它时,我得到错误:
语法错误:意外数字 在 Object.parse (本机) 在 fromJson (http://localhost:8080/WebEastGui/build/js/app-vendor.js:41198:14)
有没有办法强制 Angular 不强制解析 JSON 之类的字符串?
【问题讨论】:
标签: angularjs