lamp

JSON Extension Methods

Published 30 May 09 10:55 PM | Frederick.Chapleau

Just a little sample, modified from the ScottGu…

public static class JSONHelper
{
    public static string ToJSON(this object obj)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(obj);
    }

    public static string ToJSON(this object obj, int recursionDepth)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.RecursionLimit = recursionDepth;
        return serializer.Serialize(obj);
    }
}

-f.

Filed under:

Comments

# Frederick Chapleau .NET Tip of the Day said on May 30, 2009 10:59 PM:

Do you need to generate JSON object from C# ? Check out the JavaScriptSerializer. -f. ref: http://msdn

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Protected by FormShield
Refresh
Listen
Please enter the characters shown on the image


Code: