Hi evertbody,
I'm trying to consume a WCF webservice using jQuery. The returned Json data is:
{
"ListOfPersons":
"[
{'Id':1,'FirstName':'Foo','LastName':'Bar'},
{'Id':2,'FirstName':'Hello','LastName':'World'},
{'Id':3,'FirstName':'Tanks','LastName':'Giving'},
]"
}
These are the functions I'm using in Jquery is:
var url = 'http://path/to/webservice.svc/ReturnTheList';
$.getJSON(url, function (data) {
success: readData(data)
});
function readData(data){
alert(data.ListOfPersons[0].FirstName);
}
The problem is that the alert doesn't return anything.
And, If I modify the Json to:
{
"ListOfPersons":
[
{"Id":1,"FirstName":"Foo","LastName":"Bar"},
{"Id":2,"FirstName":"Hello","LastName":"World"},
{"Id":3,"FirstName":"Tanks","LastName":"Giving"},
]
}
(I replaced the simple quotes by double quotes and removed the double quotes before the [ and after the ]).
So I concluded that it's a problem with the returned format. The problem is that I can't modify this web service . How can I consume a "bad-formatted" json structure?
Thanks you,
Regards
EDIT:
Here is the Web Service signature:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.WrappedResponse,
ResponseFormat = WebMessageFormat.Json)]
string ReturnTheList();