Last post Mar 05, 2014 01:12 AM by GAllwood
Mar 04, 2014 06:47 PM|GAllwood|LINK
Not sure if this is the correct forum, but can anyone give me an example of calling a web API GET action that returns a simple JSON encoded object.
I have seen examples in console apps or windows desktop apps where they call HttpClient.GetAsync() to obtain a HttpResponse object. They access the Content property of the response and use an extension method to call ReadAsAsync<T>(), where T is a client
side representation of the JSON serialised server object.
It seems that Windows Store apps do not have the extention methods on HttpContent.
So, now I don't know how to convert my response string (JSON) in to my client side model.
Thanks for your help.
Mar 05, 2014 01:12 AM|GAllwood|LINK
Aha, got it.
Using the Newtonsoft Json library, I can do:
var json = await client.GetStringAsync(uri);
Product p = JsonConvert.DeserializeObjectAsync<Product>(json);