user755230
user755230

Reputation: 125

how to make json web service in asp.net?

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.

Upvotes: 5

Views: 20931

Answers (3)

Mike Gledhill
Mike Gledhill

Reputation: 29213

I spent hours Googling around, trying to find a quick, decent, readable way of creating JSON web services.

In the end, when I'd finally worked out how to do it, I went back and documented it, so I never have to face these hurdles again !!

Have a read here

(It's actually for WCF JSON web services, but also shows how to link it to a SQL Server database, and so on.)

Upvotes: 5

Peyman
Peyman

Reputation: 3138

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;

    }

Upvotes: 13

Amit
Amit

Reputation: 22086

Try this How To Create A JSON Web Service In ASP.NET

Upvotes: 3

Related Questions