/// <summary> /// 序列化指定的对象至JSON字符串 /// </summary> /// <param name="target">指定的对象</param> /// <returns>JSON字符串</returns> public static string SerializeObject(object target) { return(DynamicJsonHelper.CreateJsonString( new XStreamingElement("root", DynamicJsonHelper.CreateTypeAttr(DynamicJsonHelper.GetDynamicJsonType(target)), DynamicJsonHelper.CreateJsonNode(target)))); }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public override string ToString() { // Serialize to JsonString // <foo type="null"></foo> is can't serialize. replace to <foo type="null" /> foreach (var elem in xml.Descendants().Where(x => x.Attribute("type").Value == "null")) { elem.RemoveNodes(); } return(DynamicJsonHelper.CreateJsonString(new XStreamingElement("root", DynamicJsonHelper.CreateTypeAttr(jsonType), xml.Elements()))); }