Search code examples
javascriptjsonangularjsinternet-explorer-9ngresource

IE9 resource returing array of char instead of JSON object


I'm having a rating system with an API to handle the ratings. On the Get method is the following code:

public JToken Get(string vid) {
    JToken result = null;

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


    return result;
}

and in my service I do:

factory('Rating', ['$resource',
function ($resource) {
    var src = config.getValue("api.rating");
    return $resource(src, {}, {
        get: {
            method: 'GET',
            withCredentials: true,
            responseType: 'json'
        }
    });
}])

in Firefox and Chrome this works fine when I do:

Rating.get({ vid: $scope.video.Id }, function (res) {
          $scope.videoRating = res.Rating;
}

but in IE9 it gets an array of char from the string that is being returned. Can someone tell me what's going on, and how I can fix it?


Solution

  • I fixed it by doing the following:

    public JObject Get(string vid) {
        String result;
    
        var status = new {
            Rating = 100,
            UserRated = true
        };
        result = JsonConvert.SerializeObject(status);
    
    
        return JObject.Parse(result);
    }
    

    seems there was a problem with the Jtoken, and by doing an explicit parse to JObject it ended up working just fine