123456789101112131415161718192021222324252627282930 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization.Json;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace GWSocketClient.util
- {
- class JsonHelper
- {
- public static T parse<T>(string jsonString)
- {
- using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
- {
- return (T) new DataContractJsonSerializer(typeof(T)).ReadObject(ms);
- }
- }
-
- public static string stringify(object jsonObject)
- {
- using (var ms = new MemoryStream())
- {
- new DataContractJsonSerializer(jsonObject.GetType()).WriteObject(ms, jsonObject);
- return Encoding.UTF8.GetString(ms.ToArray());
- }
- }
- }
- }
|