【问题标题】:Which "controller" convert the XML response from a .NET WebService in JSON?哪个“控制器”以 JSON 格式转换来自 .NET WebService 的 XML 响应?
【发布时间】:2012-06-12 13:59:41
【问题描述】:

.NET 中的 WebServices(asmx,还有 wcf)使用 XML 作为信息的模式(由于 Saop 协议)。

但是在客户端,在 web 服务方法调用之后:

WebService.myOwnMethod("string", function (result) {
    console.log(result.Name);
});

我可以将结果作为 Javascript 对象进行管理。所以我认为有从 XML 到 JSON 的转换?或者直接 XML 转 Js 对象。

那么,是谁进行了这种解析?脚本管理器?

【问题讨论】:

  • 首先,你怎么调用你的web服务,你调用的是什么web服务(WCF可以发json,asmx,不能)
  • 我正在使用 asmx。我通过上面的功能在客户端调用网络服务。
  • 好的,但是如何获取 WebService 对象?您在客户端使用哪个框架?
  • .NET 4.0。我通过 ScriptManager 得到它:<asp:ServiceReference Path="~/Webservices/WebService.asmx" />
  • @Blam:请不要编辑标题!我问谁转换,而不是如何:O

标签: javascript .net xml json web-services


【解决方案1】:

您可以使用 ResponseFormat 以 JSON 格式发送数据,例如:

[WebMethod(Description = "Description of your web method")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public returntype YourMethodName()
{
}

如果您的 Web 服务方法的 responseformat 设置为 json,它将以 json 格式返回数据。

【讨论】:

  • 您需要添加一个 using 语句以供 System.Web.Script.Services 参考;
  • 我不问!我问哪个控件将 XML 转换为 Js :)
猜你喜欢
  • 1970-01-01
  • 2018-03-14
  • 2013-08-08
  • 1970-01-01
  • 2017-01-07
  • 1970-01-01
  • 2018-01-19
  • 1970-01-01
  • 2013-07-18
相关资源
最近更新 更多