I assume you want to return a JSON representation of the object
{ firstname:"John", lastname:"Smith" }
but your method signature returns a string. Serializing the ASP.Net structure correctly , serializing the response string. In other words, if your function was
string response = "foo"; return response;
No wonder if the result was
{"d":{"foo"}}
It just happens that response has double quotes that need to be escaped.
You obviously just want to hit the object. You have 2 options: -
1) use eval in your javascript to turn a string into an object, e.g.
function onSuccessCallback(retval) { var obj = eval(retval.d); }`
2) or (and this is my preferred solution), your method returns a real object, and let serializing the JSON framework make a heavy lift for you
[WebMethod] public static object getData(Dictionary<string, string> d) { var response = new { firstname = "John", lastname="Smith" }; return response; }
You will see that this generates a response that you probably originally expected (for example, {"d":{"firstname":"John", "lastname":"Smith"}}
Chris fewtrell
source share