如何获取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);
}
);
}