Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Json deserialize error
Message
From
06/05/2016 16:59:21
 
 
To
06/05/2016 16:56:36
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01635955
Message ID:
01635974
Views:
71
Once you get this working, remove any using statements you don't need.

>Here is the entire file.
>
>
>using Newtonsoft.Json;
>using System;
>using System.Collections.Generic;
>using System.ComponentModel;
>using System.Linq;
>using System.Net.Http;
>using System.Text;
>using System.Threading.Tasks;
>using m2m.Model;
>using System.Runtime.CompilerServices;
>using System.Net.Http.Headers;
>
>namespace m2m.ViewModel
>{
>    public class PromoDetailsModel : INotifyPropertyChanged
>    {
>        
>       // public List<PromoDetailsResult> Promoparent { get; set; }
>
>        private List<DetailsHeader> header;
>        public List<DetailsHeader> Header
>        {
>            get { return header; }
>            set { header = value;
>                PropertyChangedEventHandler handler = PropertyChanged;
>                handler?.Invoke(this, new PropertyChangedEventArgs("Header"));
>            }
>        }
>
>
>        public async void GetPromoDetails(int id)
>        {
>            var url = string.Format("http://tmad.us/api/v1/PromoDetails/getDetails?id={0}",id);
>            await getPromos(url);
>    }
>       
>        private async Task getPromos(string url)
>        {
>            //using (HttpClient client = new HttpClient())
>            //{
>            //   // DetailsHeader test;
>            //    client.BaseAddress = new Uri(url);
>            //    var response = await client.GetAsync(client.BaseAddress);
>            //    response.EnsureSuccessStatusCode();
>            //    var JsonResult = response.Content.ReadAsStringAsync().Result;
>            //    var promotemp = JsonConvert.DeserializeObject<List<DetailsHeader>>(JsonResult);
>            //}
>
>                        using (var client = new HttpClient())
>                        {
>
>                            client.BaseAddress = new Uri("http://tmad.us");
>                            client.DefaultRequestHeaders.Accept.Clear();
>                            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
>                            HttpResponse response = await client.GetAsync(url);
>
>                            if (response.IsSuccessStatusCode)
>                            {
>                                var result = await response.Content.ReadAsAsync<DetailsHeader>()
>                            }
>                        }
>            
>
>
>        }
>
>        public event PropertyChangedEventHandler PropertyChanged;
>
>        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
>        {
>            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
>        }
>    }
>
>}
>
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform