/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Runtime.Serialization.Json; using System.IO; using System.Text; namespace SogClient { public static class JsonConfig { public static T parse(string jsonString) { using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString))) { return (T)new DataContractJsonSerializer(typeof(T)).ReadObject(ms); } } public static T parseFile(string filePathName) { string jsonString = File.ReadAllText(filePathName); return parse(jsonString); } public static string stringify(object jsonObject) { using (var ms = new MemoryStream()) { new DataContractJsonSerializer(jsonObject.GetType()).WriteObject(ms, jsonObject); return Encoding.UTF8.GetString(ms.ToArray()); } } } }