Esempio n. 1
0
        /// <summary>
        /// Converts json string to dynamic object collections datatable.
        /// </summary>
        /// <param name="json">Json string to extend.</param>
        /// <param name="type">The type.</param>
        /// <returns>DataTable object</returns>
        public static IList ToObjects(this string json, Type type)
        {
            IList  data = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(type));
            JArray jarr = JArray.Parse(json);

            foreach (JObject jobject in jarr.Children <JObject>())
            {
                object tempObject = JsonConverterHelper.Deserialize(jobject.ToString(), type);
                data.Add(tempObject);
            }

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts json string to dynamic object datatable.
        /// </summary>
        /// <param name="json">Json string to extend.</param>
        /// <param name="type">The type.</param>
        /// <returns>DataTable object</returns>
        public static object ToObject(this string json, Type type)
        {
            JObject jobject = JObject.Parse(json);

            return(JsonConverterHelper.Deserialize(jobject.ToString(), type));
        }