$ resource获取请求和解析数据

时间:2014-05-07 02:28:39

标签: json angularjs asp.net-web-api resources

如何获取Json对象。我收到错误“SyntaxError:Unexpected token o”

以下是我的webapi和资源请求。

webapi像这样回复

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"wafId":"1","engagementProjectName":"EngagementProjectName","engagementLibraryStatus":"EngagementLibraryStatus","totalCount":"23"},{"wafId":"1","engagementProjectName":"EngagementProjectName","engagementLibraryStatus":"EngagementLibraryStatus","totalCount":"23"},{"wafId":"1","engagementProjectName":"EngagementProjectName","engagementLibraryStatus":"EngagementLibraryStatus","totalCount":"23"}]
</string>

客户端代码

factory.getSampleData = function(){

   var sampleDataCollection = $resource("/api/data/GetSampleData/");

    var collections = sampleDataCollection.get();

    collections.$promise.then(
        function onSuccess(data) {
            var d = JSON.parse(data); // getting error as  SyntaxError: Unexpected token o

           },
        function onfailed(reason) {
            alert("onfailed : " + reason);
            console.log(reason);
        }
        );

}

0 个答案:

没有答案