예제 #1
0
        /// <summary> Parses a single FormPost object from json. </summary>
        public static FormPost FromJson(JToken json)
        {
            if (json == null)
            {
                return(null);
            }

            try
            {
                FormPost obj = new FormPost();

                obj.RequestVerificationToken = json[key_token] != null ? json[key_token].Value <string>() : null;

                JEnumerable <JProperty> properties = json.Children <JProperty>();

                obj.Metadata = new Metadata();
                foreach (JProperty prop in properties.Where(x => x.Name.StartsWith(prefix_metadata)))
                {
                    obj.Metadata[prop.Name.Substring(prefix_metadata.Length + 1)] = prop.Value.Value <object>();
                }

                obj.Data = new Dictionary <string, string>();
                foreach (JProperty prop in properties.Where(x => x.Name.StartsWith(prefix_data)))
                {
                    obj.Data[prop.Name.Substring(prefix_data.Length + 1)] = prop.Value.Value <string>();
                }

                return(obj);
            }
            catch
            {
                return(null);
            }
        }
        private static List <T1> GetValuesFromJArray <T1>(JArray jarray)
        {
            List <T1> newList = new List <T1>();

            if (jarray is null)
            {
                return(newList);
            }

            foreach (JToken i in jarray.Children())
            {
                JEnumerable <JProperty> itemProperties = i.Children <JProperty>();

                foreach (JProperty myElement in itemProperties.Where(x => x.Name == "value"))
                {
                    newList.Add(TypeConverter.ConvertData <T1>((string)myElement.Value));
                }
            }

            return(newList);
        }
예제 #3
0
        protected IList <object> GetValuesFromJArray(JArray jarray, string key)
        {
            List <object> newList = new List <object>();

            if (jarray is null)
            {
                return(newList);
            }

            foreach (JToken i in jarray.Children())
            {
                JEnumerable <JProperty> itemProperties = i.Children <JProperty>();

                foreach (JProperty myElement in itemProperties.Where(x => x.Name == key))
                {
                    newList.Add((string)myElement.Value);
                }
            }

            return(newList);
        }