/// <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)))); }
private bool TrySet(int index, object value) { var type = DynamicJsonHelper.GetDynamicJsonType(value); var e = xml.Elements().ElementAtOrDefault(index); if (e == null) { xml.Add(new XElement("item", DynamicJsonHelper.CreateTypeAttr(type), DynamicJsonHelper.CreateJsonNode(value))); } else { e.Attribute("type").Value = type.ToString(); e.ReplaceNodes(DynamicJsonHelper.CreateJsonNode(value)); } return(true); }
private bool TrySet(string name, object value) { var type = DynamicJsonHelper.GetDynamicJsonType(value); var element = xml.Element(name); if (element == null) { xml.Add(new XElement(name, DynamicJsonHelper.CreateTypeAttr(type), DynamicJsonHelper.CreateJsonNode(value))); } else { element.Attribute("type").Value = type.ToString(); element.ReplaceNodes(DynamicJsonHelper.CreateJsonNode(value)); } return(true); }