如何在asp.net中制作json网络服务? [英] how to make json web service in asp.net?

查看:82
本文介绍了如何在asp.net中制作json网络服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次制作Web服务.我需要在C#中使用json来实现.我没有如何编码从数据库中获取数据的方法 任何建议.

I m making web service for the first time. and i need to make that using json in c#. I m not getting how to code the methods that fetch data from database Any suggessions.

推荐答案

您可以使用以下代码返回JSON序列化的字符串:

You can use the below code to return the JSON serialized string:

    [WebMethod(Description = "Your Description")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string FunctionName()
    {           
        // Return JSON data
        JavaScriptSerializer js = new JavaScriptSerializer();
        string retJSON = js.Serialize(Object);
        return retJSON;

    }

这篇关于如何在asp.net中制作json网络服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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