0

How to get Json object. i'm getting error as "SyntaxError: Unexpected token o"

following are my webapi and resource request.

webapi gives back like this

<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>

client code

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);
        }
        );

}
srieen
  • 59
  • 1
  • 8
  • Is your full URL same- or cross-domain? – Benjamin White May 07 '14 at 02:53
  • Same URL not a cross domain. – srieen May 07 '14 at 02:55
  • 1
    believe that's a server side issue. You're calling JSON.parse(), but you're server is returning XML (albeit with JSON inside). These threads look useful: [here](http://stackoverflow.com/questions/211348/how-to-let-an-asmx-file-output-json) and [here](http://forums.asp.net/p/1327142/2652827.aspx). I'd try a POST instead of GET. – Benjamin White May 07 '14 at 03:01

0 Answers0