Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Run time error JsonConvert.DeserializeObject
Message
De
14/04/2016 10:15:28
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
 
 
À
14/04/2016 04:00:34
Information générale
Forum:
Visual Studio
Catégorie:
Autre
Divers
Thread ID:
01634759
Message ID:
01634787
Vues:
44
>>I am very much a newbe to VS and c# so please be patient.
>>
>>I am trying to get some data through my Rest service with the end result of building a IOS/Android app using C# and Xamarin. I have going through the steps watching some Pluralsight videos and I have hit a wall. I have the following code.
>>
>>
>>            public async Task getPromos(string url)
>>            {
>>                HttpClient client = new HttpClient();
>>                client.BaseAddress = new Uri(url);
>>                var response = await client.GetAsync(client.BaseAddress);
>>                response.EnsureSuccessStatusCode();
>>                var JsonResult = response.Content.ReadAsStringAsync().Result;
>>                var promo = JsonConvert.DeserializeObject<PromoResult>(JsonResult);
>>                SetValues(promo);
>>            }
>>
>>
>>When I am in the VS IDE, and hover my mouse over I can see that PromoResult is a class as expected. When I step through the code and get the that line of code, hovering the mouse over PromoResult says that there is no object and that is where the program ends with the errors below. Not sure how to fix this. Any ideas?
>>
>>Thanks.
>>
>>
>>
>>04-13 15:43:15.120 D/Mono    (22045): Remapped public key token of retargetable assembly System from 7cec85d7bea7798e to b77a5c561934e089
>>04-13 15:43:15.120 D/Mono    (22045): The request to load the retargetable assembly System v2.0.5.0 was remapped to System v2.0.5.0
>>04-13 15:43:15.122 D/Mono    (22045): Unloading image System.dll [0x687ebbe0].
>>04-13 15:43:15.122 D/Mono    (22045): Image addref System[0x687ed778] -> System.dll[0x66e3b8d0]: 4
>>04-13 15:43:15.123 D/Mono    (22045): Assembly Ref addref Newtonsoft.Json[0x661d6b50] -> System[0x66e50628]: 12
>>04-13 15:43:15.187 D/Mono    (22045): Remapped public key token of retargetable assembly System.Runtime.Serialization from 7cec85d7bea7798e to b77a5c561934e089
>>04-13 15:43:15.187 D/Mono    (22045): The request to load the retargetable assembly System.Runtime.Serialization v2.0.5.0 was remapped to System.Runtime.Serialization v2.0.5.0
>>04-13 15:43:15.189 D/Mono    (22045): Unloading image System.Runtime.Serialization.dll [0x688487b8].
>>04-13 15:43:15.189 D/Mono    (22045): Image addref System.Runtime.Serialization[0x68844e08] -> System.Runtime.Serialization.dll[0x6793c188]: 4
>>04-13 15:43:15.189 D/Mono    (22045): Assembly Ref addref Newtonsoft.Json[0x661d6b50] -> System.Runtime.Serialization[0x6790e188]: 3
>>Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
>>04-13 15:43:15.451 D/Mono    (22045): Assembly Ref addref m2m[0x65d48a08] -> System.Diagnostics.Debug[0x66154e28]: 3
>>
>
>Probably cause is that you are accessing JsonResult before the ReadAsStringAsync() completes. Try:
var JsonResult = await response.Content.ReadAsStringAsync().Result;
I tried that and the IDE gave me an error. I do have an await in the GetAysnc call and I have verified stepping through the code that JsonResult is populated. PromoResult is defined here:
namespace m2m { 
    public class PromoResult {
        public PromotionObserver promotionObserver { get; set; }
    }
}

namespace m2m
{
    public class PromotionObserver
    {
        public int autocouponlinkpk { get; set; }
        public int subscriberfk { get; set; }
        public DateTime enddate { get; set; }
        public bool hidesharebutton { get; set; }
        public bool iscoupon { get; set; }
        public string coupdescrp { get; set; }
        public bool globalcoupon { get; set; }
        public string imageurl { get; set; }
        public string market_descrp { get; set; }
        public string globallogo { get; set; }

    }
}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform