Skip to content

Instantly share code, notes, and snippets.

@yujuwon
Created February 19, 2013 02:31
Show Gist options
  • Save yujuwon/4982612 to your computer and use it in GitHub Desktop.
Save yujuwon/4982612 to your computer and use it in GitHub Desktop.
[Serializable]
class JsonIn
{
internal string function;
internal string type;
}
[Serializable]
class JsonOut
{
internal string result;
internal string content;
}
class Program
{
static void Main(string[] args)
{
JsonIn jsonIn = new JsonIn();
jsonIn.function = "test";
jsonIn.type = "test";
// Object to Stream
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer dataSerializer = new DataContractJsonSerializer(typeof(JsonIn));
dataSerializer.WriteObject(stream, JsonIn);
// Stream to Object
stream.Position = 0;
JsonIn jsonIn2 = dataSerializer.ReadObject(stream) as JsonIn;
stream.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment