【问题标题】:IE9 resource returing array of char instead of JSON objectIE9 资源返回 char 数组而不是 JSON 对象
【发布时间】:2015-07-10 07:43:07
【问题描述】:

我有一个带有 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 数组。 谁能告诉我发生了什么,我该如何解决?

【问题讨论】:

标签: javascript json angularjs internet-explorer-9 ngresource


【解决方案1】:

我通过以下操作修复了它:

public JObject Get(string vid) {
    String result;

    var status = new {
        Rating = 100,
        UserRated = true
    };
    result = JsonConvert.SerializeObject(status);


    return JObject.Parse(result);
}

似乎 Jtoken 存在问题,通过对 JObject 进行显式解析,它最终可以正常工作

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2018-07-03
    • 1970-01-01
    • 2020-04-11
    • 2018-07-05
    相关资源
    最近更新 更多