Ejemplo n.º 1
0
        /// <summary>
        /// Parses a JSON snippet of an array value.
        /// </summary>
        /// <typeparam name="T">The type of the object to parse the array items into.</typeparam>
        /// <param name="json">The string containing the JSON snippet, begining and ending with square brackets.</param>
        /// <param name="typeResolver">A class to help resolving dynamic or unknown types.</param>
        /// <returns>The parsed array.</returns>
        public static T[] LoadArray <T>(string json, JsonTypeResolver typeResolver)
        {
            int i = 0;

            IList list = ReadArray(json, ref i, typeof(T[]), typeResolver ?? JsonTypeResolver.FromAssemblyMappings <T>(), true);

            T[] array = new T[list.Count];

            list.CopyTo(array, 0);
            return(array);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses a JSON snippet of a value.
        /// </summary>
        /// <typeparam name="T">The type of the object to parse.</typeparam>
        /// <param name="json">The string containing the JSON snippet.</param>
        /// <param name="typeResolver">A class to help resolving dynamic or unknown types.</param>
        /// <returns>The parsed value.</returns>
        public static T LoadObject <T>(string json, JsonTypeResolver typeResolver) where T : new()
        {
            int i = 0;

            return((T)ReadValue(json, ref i, null, typeof(T), typeResolver ?? JsonTypeResolver.FromAssemblyMappings <T>()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a JSON string into an existing object.
        /// </summary>
        /// <typeparam name="T">The type of the object to parse the JSON string into.</typeparam>
        /// <param name="this">The object to parse the JSON string into.</param>
        /// <param name="json">The JSON string to parse.</param>
        /// <param name="typeResolver">A class to help resolving dynamic or unknown types.</param>
        public static void LoadFromJson <T>(this T @this, string json, JsonTypeResolver typeResolver)
        {
            int start = 0;

            LoadFromJson(@this, json, ref start, typeResolver ?? JsonTypeResolver.FromAssemblyMappings <T>());
        }