我希望在一个Web方法中对Json和Xml做出响应 [英] i want response in Json and Xml in one web methode

查看:45
本文介绍了我希望在一个Web方法中对Json和Xml做出响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的网络方法

i成功获得Json回复。

here is my web method
i am getting Json response succesfully.

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void GetUserDetailJSON(string email, string format)
    {
        if (format == "Json")
        {
            Model.Customer cust = Biz.BAL.GetUserDetail(email); //this get data.
            JavaScriptSerializer js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(cust));
        }
        else
        {
              Model.Customer cust = Biz.BAL.GetUserDetail(email); //this get data.
//cust is a class object and what i do here for xml response where my return type is void           

            
        }
    }

推荐答案

了解如何将 XML 作为一个 string 并在我的博客中的客户端阅读 - 使用AJAX WebMethod从DataTable绑定DropDownList [ ^ ]。



您只需找到一种方法将您拥有的数据转换为XML字符串。
See how you can sen XML as a string and read it in client side in my blog - Bind DropDownList from DataTable using AJAX WebMethod[^].

You just need to find a way to convert the data you have to a XML string.


这篇关于我希望在一个Web方法中对Json和Xml做出响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆