/// <summary> /// Directly serializes <see cref="object"/> to JSON <see cref="string"/>. /// </summary> /// <param name="obj">The <see cref="object"/> to be serialized.</param> /// <returns>The JSON <see cref="string"/> serialized.</returns> public static string Stringify(object obj) { if (obj is string) { return(obj as string); } if (obj is JSONEntity) { return(StringAnalyzer.Analyze(obj as JSONEntity)); } return(DirectAnalyzer.Analyze(obj)); }
/// <summary> /// Directly deserializes JSON <see cref="string"/> to <see cref="object"/>. /// </summary> /// <typeparam name="T">The target <see cref="Type"/>.</typeparam> /// <param name="str">The JSON <see cref="string"/> to be deserialized.</param> /// <returns>The <see cref="object"/> deserialized.</returns> public static T Parse <T>(string str) { if (typeof(T).IsAssignableFrom(typeof(string))) { return((T)(object)str); } if (typeof(T) == typeof(JSONEntity)) { return((T)(object)StringAnalyzer.Analyze(str)); } if (typeof(T).IsSubclassOf(typeof(JSONEntity))) { throw new UnexpectedTypeException("Use JSON.Deserialize(string) instead."); } return(DirectAnalyzer.Analyze <T>(str)); }