Reputation: 9
I'm building a mobile application that recive data from a server as json object , im using asp.net / sql server database to build the server , i dont know how to retrive data from sql database and convert it to json object that the client can request I'm not using asp.net MVC any help to start !
Upvotes: 0
Views: 245
Reputation: 12481
You need to build some sort of web service that handles this request.
Here's a couple of options.
Upvotes: 0
Reputation: 22456
Check out JSON.net. It is a JSON serialization framework that has also been adopted by ASP.NET MVC Web API. You can install it via NuGet.
Upvotes: 1
Reputation: 39248
If you're using ASP.NET MVC you can create a controller that returns JSON. In your controller do:
return Json(yourObject);
You can also do it using the Web API. It will do content negotiation for you and return the data in the format you request it (JSON, XML, etc.).
Web API reference: Getting Started with ASP.NET Web API 2
Upvotes: 0
Reputation: 762
You can use JavaScriptSerializer class, for example:
SomeType obj = ....
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(obj);
Then you should instruct browser to download json, here you can see: Returning JSON object from an ASP.NET page
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.Write(json);
Response.End();
You can use other serializers too: http://habrahabr.ru/post/133778/
Upvotes: 0