卸下" D"从ASP.Net Web服务的JSON输出对象对象、ASP、QUOT、Net

2023-09-07 02:08:12 作者:半夜洗屁股

我有一些javascript code表示处理JSON输出从用框架2.0 asp.net web服务。现在我需要支持从Framework 3.5的Web服务返回的数据。

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.

我的JavaScript code假定对象为返回值,这在2.0正常工作清单。然而,在框架3.5,列表被包裹在一个D的对象。有没有什么办法可以去除D的包装,只是返回列表?

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?

我会preFER来解决这个问题onthe服务器端

I would prefer to fix this onthe server side

推荐答案

您不能配置3.5+服务不回 .D 。这是很好的,它的存在也是如此,因为它存在时,外JSON实体是一个数组一个棘手的JSON劫持场景保护。

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的客户端代理自动隐藏 .D 你。如果它在你的方式,我假设你正在使用像jQuery来调用服务? 您可以正常化 .D jQuery中使用其DataFilter回调,例如。

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.