Esempio n. 1
0
        public async Task <List <InstantObject> > GetFoods(String query)
        {
            HttpResponseMessage response = await client.GetAsync("search/instant?query=" + query);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                try
                {
                    var     res = new List <InstantObject>();
                    JObject obj = JsonConvert.DeserializeObject(result) as JObject;

                    foreach (var item in obj["common"].ToList())
                    {
                        res.Add(InstantObject.FromJson(item.ToString()));
                    }

                    return(res);
                }
                catch (Exception)
                {
                    return(new List <InstantObject>());
                }
            }

            return(new List <InstantObject>());
        }
Esempio n. 2
0
 public static string ToJson(this InstantObject self) => JsonConvert.SerializeObject(self, NutritionAPI.Converter.Settings);