如何在服务器端 把对象(DataSet, struct..)生成 符合 客户端 ajax(jquery)xml格式 的 文档。

ruoge2007 2011-01-15 06:52:06
当前DataSet是返回客户端用这种方式实现的:
[WebMethod(true)]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet area_getAreaBJ()
{
....
}
对 struct 是这样返回客端的:
[WebMethod(true)]
public PostRecord user_GetPostRecord( string strParam)
{
...
}
现在在服务器端直接生成 xml的格式,统一返回如下的结构体:
struct AjaxResponse
{
public string strRst;
public string strJS;
public string strCont;
};

strCont 为 xml或json 结构的数据。
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruoge2007 2011-01-21
  • 打赏
  • 举报
回复
newtonsoft,好似是这个,可以实现
ruoge2007 2011-01-16
  • 打赏
  • 举报
回复
用DataSet.GetXml() 不可以;
当这样用:
[WebMethod(true)]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet area_getAreaBJ()
{
....
return DataSet.GetXml();
}
在 jquery那报错。


[WebMethod(true)]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet area_getAreaBJ()
{
....
}
ruoge2007 2011-01-16
  • 打赏
  • 举报
回复
不知道System.Web.Script.Services.ResponseFormat.Xml 这种xml跟 dataset.getxml有啥区别。
wuyq11 2011-01-15
  • 打赏
  • 举报
回复
dataset.writexml生产xml
list<t>序列化为XML
  • 打赏
  • 举报
回复
DataSet可直接转成XML格式
string DataSet.GetXml() 要得到一个XML格式的字符串
还有DataSet.WriteXml()直接写到文件或者流
DataSet.ReadXml从文件读取XML格式内容并填充DataSet

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧