Why does web service return data as msg.d

天涯浪子 提交于 2019-11-30 20:24:24

It's a bit of a security feature as part of ASP.NET. It will always be there as long as you don't change serializers. David Ward's blog (now defunct) said what it is:

This is the case with all ASMX services JSON serialized through the ASP.NET AJAX Extensions in ASP.NET 3.5. Even if you’re only returning a scalar return value, such as a string, int, or boolean, the result will always be enclosed within the “d”.

And the why:

{"d": 1 }

Is not a valid JavaScript statement, where as this:

[1]

Is.

So the wrapping of the "d" parameter prevents direct execution of the string as script. No Object or Array constructor worries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!