Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
I Want to return Json Webservice in Asp.net Using C# . This is return Webservice i Want.

{ "Cargo": [ { "status": "pickup", "datetime": "" }, { "status": "InTransit",

"datetime": "" }, { "status": "ReachedBLR", "datetime": "" }, { "status":

"StartedDEL", "datetime": "" }, { "status": "InTransit", "datetime": "" }, { "status": "ReachedDEL", "datetime": "" }] }..

Please help me by giving code
Thanks In advance..
Posted
Updated 26-Sep-17 22:40pm

 
Share this answer
 
Comments
Member 10556609 1-Apr-14 6:59am    
Sorry I Want to Get That Data From SqlServer
 
Share this answer
 
Comments
Member 10556609 1-Apr-14 6:59am    
Sorry I Want to Get That Data From SqlServer
JSON is nothing more than a data exchange format delivered over string...
So if you have the method that creates the JSON in the server, all what you have to do is turn it into a string (stringify) and return it as a string from your method...
C#
[WebMethod]
public string GetCargoInfo()
{
  return("{\"Cargo\":[...]}");
}
 
Share this answer
 
Comments
Member 10556609 1-Apr-14 6:59am    
Sorry I Want to Get That Data From SqlServer
Kornfeld Eliyahu Peter 1-Apr-14 7:02am    
How do you get it?
Member 10556609 1-Apr-14 7:06am    
I Create Table In SqlServer..That Tables Data Will Get It From Webservice.LIKE this
{ "Cargo": [ { "status": "pickup", "datetime": "" }, { "status": "InTransit",

"datetime": "" }, { "status": "ReachedBLR", "datetime": "" }, { "status":

"StartedDEL", "datetime": "" }, { "status": "InTransit", "datetime": "" }, { "status": "ReachedDEL", "datetime": "" }] }.. how to get this
Kornfeld Eliyahu Peter 1-Apr-14 7:08am    
I have some trouble with your explanation...Let me try if I got you...
You have data in SQL and you want to create a web service that returns that data in JSON form, like in your sample...
Please clarify...
Member 10556609 1-Apr-14 7:11am    
Yes Absolutely.. This Is i want..
convert your json data to string and then in javascript convert the string to json


----Json.convert(string)
--------------------------------------------------------------------------------

C#
public string json()
{

    JavaScriptSerializer a= new JavaScriptSerializer();
    var haha = new
    {
        nombre = "antonio",
        edad = 21
    };

    return a.Serialize ( new {result  = haha });

}
 
Share this answer
 
v2
i think that, you should using WCF instantof Webservice
[ServiceContract]
public partial class BookmarkService
{
...
[WebInvoke(Method = "POST", RequestFormat=WebMessageFormat.Json,
UriTemplate = "users/{username}/bookmarks?format=json")]
[OperationContract]
void PostBookmarkAsJson(string username, Bookmark newValue)
{
HandlePostBookmark(username, newValue);
}
[WebGet(ResponseFormat= WebMessageFormat.Json,
UriTemplate = "users/{username}/bookmarks/{id}?format=json")]
[OperationContract]
Bookmark GetBookmarkAsJson(string username, string id)
{
HandleGetBookmark(username, id);
}
...
}

more detail here: https://msdn.microsoft.com/en-us/library/dd203052.aspx[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900