Beispiel #1
0
        private async void GetSymptoms(string plant)
        {
            var url = $"{symptURL}";
            var obj = new { name = plant };

            using (var client = new HttpClient())
            {
                var payload  = JsonConvert.SerializeObject(obj);
                var content  = new StringContent(payload, Encoding.UTF8, @"application/json");
                var response = await client.PostAsync(url, content);

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

                    symptList = Unwrap(result);
                    //SymptomListTxt.Text += result;
                    int count = 1;
                    foreach (string sympt in symptList.Symptoms)
                    {
                        SymptomListTxt.Text += $@"{count++} {sympt}";
                    }
                }
                else
                {
                    await DisplayAlert("Plant search", "Unknown plant", "OK");
                }
            }
        }
Beispiel #2
0
        private SymptomsList Unwrap(string result)
        {
            result.Replace("[", String.Empty).Replace("]", String.Empty).Replace("{", String.Empty).Replace("}", String.Empty);
            SymptomsList list = new SymptomsList();

            list.Symptoms = result.Split(',');
            return(list);
        }