Search code examples
asp.netjavascriptjson.net-3.5.net-2.0

Removing the "d" object from ASP.Net web service json output


I have some javascript code that processes json output from asp.net web services built with framework 2.0. Now I need to support data returned from framework 3.5 web services.

My javascript code assumes a list of objects as return value, which works fine in 2.0. However In framework 3.5, the list is wrapped in a "d" object. Is there any way I can remove the "d" wrapper and just return the list?

I would prefer to fix this onthe server side


Solution

  • You can't configure 3.5+ services not to return the .d. It's good that it's there too, because it protects from a tricky JSON hijacking scenario that exists when the outer JSON entity is an array.

    ASP.NET AJAX's client-side proxies automatically hide the .d from you. If it's getting in your way, I'm assuming you're using something like jQuery to call the service? You can normalize the .d in jQuery by using its DataFilter callback, for example.