Created
December 24, 2010 14:57
-
-
Save follesoe/754314 to your computer and use it in GitHub Desktop.
Bridging windows and web applications using JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string ToJSON<T>(this T obj) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
try | |
{ | |
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); | |
serializer.WriteObject(ms, obj); | |
return Encoding.UTF8.GetString(ms.ToArray()); | |
} | |
finally | |
{ | |
ms.Close(); | |
ms.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment