/// <summary> /// AopObject序列化 /// </summary> /// <param name="obj"></param> /// <returns></returns> private String Serialize(AopObject obj) { // 使用AopModelParser序列化对象 AopModelParser parser = new AopModelParser(); return(parser.serializeAopObject(obj)); }
private string Serialize(AopObject obj) { AopModelParser aopModelParser = new AopModelParser(); JsonObject value = aopModelParser.serializeAopObject(obj); return(JsonConvert.ExportToString(value)); }
/// <summary> /// 添加一个新的键值对。空键或者空值的键值对将会被忽略。 /// </summary> /// <param name="key">键名称</param> /// <param name="value">键对应的值,目前支持:string, int, long, double, bool, DateTime类型</param> public void Add(string key, object value) { string strValue; if (value == null) { strValue = null; } else if (value is string) { strValue = (string)value; } else if (value is Nullable <DateTime> ) { Nullable <DateTime> dateTime = value as Nullable <DateTime>; strValue = dateTime.Value.ToString(DATE_TIME_FORMAT); } else if (value is Nullable <int> ) { strValue = (value as Nullable <int>).Value.ToString(); } else if (value is Nullable <long> ) { strValue = (value as Nullable <long>).Value.ToString(); } else if (value is Nullable <double> ) { strValue = (value as Nullable <double>).Value.ToString(); } else if (value is Nullable <bool> ) { strValue = (value as Nullable <bool>).Value.ToString().ToLower(); } else if (value is ICollection) { AopModelParser parser = new AopModelParser(); object jo = parser.serializeArrayValue(value as ICollection); JsonSerializerSettings jsetting = new JsonSerializerSettings(); jsetting.NullValueHandling = NullValueHandling.Ignore; strValue = JsonConvert.SerializeObject(jo, Formatting.None, jsetting); } else if (value is AopObject) { AopModelParser parser = new AopModelParser(); object jo = parser.serializeAopObject(value as AopObject); JsonSerializerSettings jsetting = new JsonSerializerSettings(); jsetting.NullValueHandling = NullValueHandling.Ignore; strValue = JsonConvert.SerializeObject(jo, Formatting.None, jsetting); } else { strValue = value.ToString(); } this.Add(key, strValue); }
/// <summary> /// AopObject序列化 /// </summary> /// <param name="obj"></param> /// <returns></returns> private String Serialize(AopObject obj) { // 使用AopModelParser序列化对象 AopModelParser parser = new AopModelParser(); IDictionary <object, object> jo = parser.serializeAopObject(obj); JsonSerializerSettings jsetting = new JsonSerializerSettings(); jsetting.NullValueHandling = NullValueHandling.Ignore; return(JsonConvert.SerializeObject(jo, Formatting.None, jsetting)); }
/// <summary> /// AopObject序列化 /// </summary> /// <param name="obj"></param> /// <returns></returns> private String Serialize(AopObject obj) { // 使用AopModelParser序列化对象 AopModelParser parser = new AopModelParser(); JsonObject jo = parser.serializeAopObject(obj); // 根据JsonObject导出String格式的Json String result = JsonConvert.ExportToString(jo); return(result); }