What is the best approach to get value from:
{"profileObj":{"Name":"xxx","FirstName":"xxx","FastName":"xxx","Email":"xxx"}}
CodePudding user response:
try this using System.Text.Json
//your json
var json= "{\"profileObj\":{\"Name\":\"xxx\",\"FirstName\":\"xxx\",\"FastName\":\"xxx\",\"Email\":\"xxx\"}}";
using System.Text.Json;
.....
var jD= JsonSerializer.Deserialize<Root>(json);
var value =jD.profileObj;
var name= value.Name;
or you can install Newtonsoft.Json nuget package and use this code
using Newtonsoft.Json;
.....
var jD = JsonConvert.DeserializeObject<Root>(json);
......
classes
public class ProfileObj
{
public string Name { get; set; }
public string FirstName { get; set; }
public string FastName { get; set; }
public string Email { get; set; }
}
public class Root
{
public ProfileObj profileObj { get; set; }
}