Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static string SerializeJSON(object graph) {
- using(MemoryStream ms = new MemoryStream()) {
- new DataContractJsonSerializer(graph.GetType()).WriteObject(ms,graph);
- ms.Position = 0;
- using(StreamReader reader = new StreamReader(ms)) {
- return reader.ReadToEnd();
- }
- }
- }
- static T DeSerializeJSON<T>(string json) {
- using(MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(json))) {
- ms.Position = 0;
- return (T)new DataContractJsonSerializer(typeof(T)).ReadObject(ms);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment