开发者

Return Data in JSON format?

How to return my data from a method (WebMethod) as a JSON Data from a web service i have tried with the

The class whose object i create ,

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)]

but 开发者_StackOverflowit does not return data in the above format but rather it returns in the XML format ????

Thanks . Regards


You need to specify that you can accept json in your GET request, ie: this needs to appear in the header of the request:

Content-Type: application/json


http://json.codeplex.com/

This is an open source library for doing this sort of thing


Try adding this to your system.web area of the web.config file...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜