Beispiel #1
0
        public dynamic GetValueListFromM3ResultByMultipleSelectors(JObject jObject, List <string> keys, bool outputAll, bool metadata)
        {
            List <dynamic> resultList = new List <dynamic>();

            try
            {
                var    index      = metadata == true ? 3 : 2;
                string jsonString = jObject.Children().ToList()[index].ToString().Remove(0, 12);

                var           list   = JsonConvert.DeserializeObject <JsonParent[]>(jsonString);
                List <object> result = new List <object>();

                if (outputAll || keys.Count <= 0)
                {
                    keys = list.FirstOrDefault() != null?list.FirstOrDefault().NameValue.Select(a => a.Name).ToList() : new List <string>();
                }

                for (int i = 0; i < list.Length; i++)
                {
                    JsonParent jsonParent = list[i];

                    Dictionary <string, string> dictionary = new Dictionary <string, string>();

                    foreach (string key in keys)
                    {
                        JsonChild child = jsonParent.NameValue.Where(a => a.Name.Equals(key)).FirstOrDefault <JsonChild>();

                        if (child != null)
                        {
                            dictionary.Add(key, child.Value.TrimEnd());
                        }
                    }

                    resultList.Add(dictionary);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
            return(resultList);
        }
Beispiel #2
0
        public List <T> GetValueListFromM3ResultByMultipleSelectors <T>(JObject jObject, IList <string> keys, bool metadata)
        {
            List <T> resultList = new List <T>();

            try
            {
                var    index      = metadata == true ? 3 : 2;
                string jsonString = jObject.Children().ToList()[index].ToString().Remove(0, 12);

                var           list   = JsonConvert.DeserializeObject <JsonParent[]>(jsonString);
                List <object> result = new List <object>();

                for (int i = 0; i < list.Length; i++)
                {
                    JsonParent jsonParent = list[i];

                    Dictionary <string, string> dictionary = new Dictionary <string, string>();

                    foreach (string key in keys)
                    {
                        JsonChild child = jsonParent.NameValue.Where(a => a.Name.Equals(key)).FirstOrDefault <JsonChild>();

                        if (child != null)
                        {
                            dictionary.Add(key, child.Value.TrimEnd());
                        }
                    }

                    var serialized = JsonConvert.SerializeObject(dictionary);
                    T   data       = JsonConvert.DeserializeObject <T>(serialized);

                    resultList.Add(data);

                    dictionary.Clear();
                }
            }
            catch (Exception e)
            {
                return(null);
            }
            return(resultList);
        }