IE9 资源返回 char 数组而不是 JSON 对象
IE9 resource returing array of char instead of JSON object
我有一个带有 API 的评级系统来处理评级。在 Get
方法上是以下代码:
public JToken Get(string vid) {
JToken result = null;
var status = new {
Rating = 100,
UserRated = true
};
result = JsonConvert.SerializeObject(status);
return result;
}
在我的服务中,我这样做:
factory('Rating', ['$resource',
function ($resource) {
var src = config.getValue("api.rating");
return $resource(src, {}, {
get: {
method: 'GET',
withCredentials: true,
responseType: 'json'
}
});
}])
在 Firefox 和 Chrome 中,这在我这样做时工作正常:
Rating.get({ vid: $scope.video.Id }, function (res) {
$scope.videoRating = res.Rating;
}
但在 IE9 中,它从返回的字符串中获取一个 char 数组。
谁能告诉我这是怎么回事,我该如何解决?
我通过执行以下操作修复了它:
public JObject Get(string vid) {
String result;
var status = new {
Rating = 100,
UserRated = true
};
result = JsonConvert.SerializeObject(status);
return JObject.Parse(result);
}
似乎 Jtoken 有问题,通过对 JObject
进行显式解析,它最终工作正常
我有一个带有 API 的评级系统来处理评级。在 Get
方法上是以下代码:
public JToken Get(string vid) {
JToken result = null;
var status = new {
Rating = 100,
UserRated = true
};
result = JsonConvert.SerializeObject(status);
return result;
}
在我的服务中,我这样做:
factory('Rating', ['$resource',
function ($resource) {
var src = config.getValue("api.rating");
return $resource(src, {}, {
get: {
method: 'GET',
withCredentials: true,
responseType: 'json'
}
});
}])
在 Firefox 和 Chrome 中,这在我这样做时工作正常:
Rating.get({ vid: $scope.video.Id }, function (res) {
$scope.videoRating = res.Rating;
}
但在 IE9 中,它从返回的字符串中获取一个 char 数组。 谁能告诉我这是怎么回事,我该如何解决?
我通过执行以下操作修复了它:
public JObject Get(string vid) {
String result;
var status = new {
Rating = 100,
UserRated = true
};
result = JsonConvert.SerializeObject(status);
return JObject.Parse(result);
}
似乎 Jtoken 有问题,通过对 JObject
进行显式解析,它最终工作正常