internal static object Deserialize(JSerializer serializer, string input, Type type, int depthLimit) { if (input == null) { throw new ArgumentNullException("input"); } if (input.Length > serializer.MaxJsonLength) { throw new ArgumentException(AtlasWeb.JSON_MaxJsonLengthExceeded, "input"); } var o = JObjectDeserializer.BasicDeserialize(input, depthLimit, serializer); return(JObjectConverter.ConvertObjectToType(o, type, serializer)); }
private object DeserializeInternal(int depth) { if (++depth > _depthLimit) { throw new ArgumentException(_s.GetDebugString(AtlasWeb.JSON_DepthLimitExceeded)); } char?c = _s.GetNextNonEmptyChar(); if (c == null) { return(null); } _s.MovePrev(); if (IsNextElementDateTime()) { return(DeserializeStringIntoDateTime()); } if (IsNextElementObject(c)) { var dict = DeserializeDictionary(depth); // Try to coerce objects to the right type if they have the __serverType if (dict.ContainsKey(JSerializer.ServerTypeFieldName)) { return(JObjectConverter.ConvertObjectToType(dict, null, _serializer)); } return(dict); } if (IsNextElementArray(c)) { return(DeserializeList(depth)); } if (IsNextElementString(c)) { return(DeserializeString()); } return(DeserializePrimitiveObject()); }
/// <summary> /// 将指定的对象转换成指定的类型。 /// </summary> /// <param name="obj">要转换的对象。</param> /// <param name="targetType">对象要转换为的类型。</param> /// <returns>序列化的 JSON 字符串。</returns> public object ConvertToType(object obj, Type targetType) { return(JObjectConverter.ConvertObjectToType(obj, targetType, this)); }
/// <summary> /// 将给定对象转换为指定类型。 /// </summary> /// <typeparam name="T"><paramref name="obj"/> 将转换成的类型。</typeparam> /// <param name="obj">要转换的对象</param> /// <returns>已转换成目标类型的对象。</returns> public T ConvertToType <T>(object obj) { return((T)JObjectConverter.ConvertObjectToType(obj, typeof(T), this)); }