Saturday, July 17, 2010

c# toJson

Nice extension method if you work allot with ajax/javascript/linq.

public static string ToJson(this object o)
{
return (JsonConvert.SerializeObject(o));
}

Can call from code.

example:
[WebMethod]
public string GetAllPoultry(){
var q = from b in data.Chicken select b;
return q.ToJson();
}

No comments:

Post a Comment