How do I get values ​​from the Json object in Xamarin Form

advertisements

Please i need help, i need to get values for UserID and UserID from the json Object below

{"data":{"UserID":"MS100000041","RoleID":5}}

This is my code:

public class UserDetails
{
    public string UserID { get; set; }
    public int RoleID { get; set; }
}

public  async Task Login(string url)
{
    try
    {
        var uri = new Uri(url);
        HttpClient myClient = new HttpClient();

        var response = await myClient.GetAsync(uri);
        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync();
            var Item = JsonConvert.DeserializeObject<UserDetails>(content);
            string userid = Item.UserID;

            int roleid= Item.RoleID;
        }
        else
        {
            Application.Current.Properties["response"] = response;
        }

    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex);
    }
}

But this value userid and roleid are showing null. Please how do i get these value


According with the JSON provided, you must access to UserID and RoleID like Item.data.UserID and Item.data.RoleID