Skip to content Skip to sidebar Skip to footer

Create List Of Objects From Json Object With Objects In Xamarin For Android

I`m using JSON.net and I'm trying to get a list of Expense objects from JSON like this: {'ApplicationUser': null, 'Currency': 1, 'Description': 'Moj pierwszy portfel', 'Expenses':

Solution 1:

Without getting too far into details, using System.Net.Http.HttpClient and a JSON library like Newtonsoft.Json or ServiceStack.Text, this would be reasonably simple. Using Newtonsoft.Json, you might be looking for something like this:

using System.Net.Http;
using Newtonsoft.Json;

...

using (var client = new HttpClient())
{
    ...

    var response = await client.GetAsync(url);
    response.EnsureSuccessStatusCode();

    string json = await response.Content.ReadAsStringAsync();
    var result = JsonConvert.DeserializeObject<RootObject>(json);

    ...
}

Post a Comment for "Create List Of Objects From Json Object With Objects In Xamarin For Android"