I am trying to deserialize just part of my JSON response when I call my function and then return it as a viewmodel but I can't seem to access an inner part of the JSON when I do this. The function in question is this,
// GetUserInfoTest method gets the currently authenticated user's information from the Web API
public IdentityUserInfoViewModel GetUserInfo()
{
using (var client = new WebClient().CreateClientWithToken(_token))
{
var response = client.GetAsync("http://localhost:61941/api/Account/User").Result;
var formattedResponse = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<IdentityUserInfoViewModel>(formattedResponse, jsonSettings);
}
}
I am able to setup an HttpClient with a token of an already authenticated user, and now I just need to get information regarding them by making a call to my API. Here is the viewmodel I am trying to fit the JSON into,
// Custom view model for an identity user
/// <summary>Custom view model to represent an identity user and employee information</summary>
public class IdentityUserInfoViewModel
{
/// <summary>The Id of the Identity User</summary>
public string Id { get; set; }
/// <summary>The Username of the Identity User</summary>
public string UserName { get; set; }
/// <summary>The Email of the Identity User</summary>
public string Email { get; set; }
/// <summary>Active status of the user</summary>
public bool Active { get; set; }
/// <summary>The Roles associated with the Identity User</summary>
public List<string> Roles { get; set; }
}
And the sample response,
{
"Success":true,
"Message":null,
"Result":{
"Id":"BDE6C932-AC53-49F3-9821-3B6DAB864931",
"UserName":"user.test",
"Email":"[email protected]",
"Active":true,
"Roles":[
]
}
}
As you can see here, I just want to get the Result JSON and deserialize it into the IdentityUserInfoViewModel but I just can't seem to figure out how to go about doing it. It feels like something simple that I'll be kicking myself in the butt about later but can't seem to grasp what it is. Any ideas?