【发布时间】:2011-06-11 18:43:54
【问题描述】:
如何将我的数据从方法 (WebMethod) 作为 JSON 数据从我尝试过的 Web 服务返回
我创建对象的类,
public class Questionnaire
{
public int QuestionnaireId { get; set; }
public string QuestionnaireName { get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetUserQuestionnaire2()
{
return new Questionnaire
{
QuestionnaireId = 1234,
QuestionnaireName = string.Format("{0} {1}", "Microsoft", 1234)
};
}
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
但它不以上述格式返回数据,而是以XML格式返回????
谢谢。 问候
【问题讨论】:
-
您能否发布一些您的 WebMethod 的额外代码 sn-ps 以及您如何调用 WebMethod。在您的用例中缺少这么多变量的情况下,很难制定一个答案。
-
是的。我已经添加了 WebMethod 以及我想要作为 JSON 数据返回其对象的类
标签: .net web-services