User-1686118291 posted
<ArrayOfEmployee xmlns="http://schemas.datacontract.org/2004/07/CR.WebServices.Model.EntityFramework" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<Email>fnln@mycompany.com</Email>
<EmployeeCode>12345</EmployeeCode>
<EmployeeName>xyz,pqr</EmployeeName>
</Employee>
<Employee>
<Email>fnln1@mycompany.com</Email>
<EmployeeCode>12346</EmployeeCode>
<EmployeeName>hij,klm</EmployeeName>
</Employee>
</ArrayOfEmployee>
I have a REST API service http://services.mycompany.com/Employees/ and browse this service results XML as shown above. I want to read via Ajax/Json call. I added a simple script
$.getJSON('http://services.mycompany.com/Employees/'
).done(function (result, status, xhr) {
alert(result.length);
}).fail(function (xhr, status, error) {
alert("Result: " + status + " : " + error + ":" + xhr.status + " :" + xhr.statusText)
});
The output alert always throw the following result:
Result: parsererror : SyntaxError: Unexpected token < in JSON at position 0 : 200 :OK
Will you please help troubleshooting? Do I have to convert xml to JSON? I verified in Fiddler debugging and I see that the 'url' has the complete xml value however it never produce result and always display the parseerror as stated.
All I need is total employees returned from the web service count. In the above case, it should alert me as "2". Any other easiest way to get the result would also work but it should work in .aspx page.