Answers for "c# deserialize object / class newtonsoft"

C#
0

c# deserialize object / class newtonsoft

// Create a class of the json
public class Account
{
   	public string Email { get; set; }
    public bool Active { get; set; }
    public DateTime CreatedDate { get; set; }
    public IList<string> Roles { get; set; }
}

// This is an example of the json format to deserialize
string json = @"{
  'Email': '[email protected]',
  'Active': true,
  'CreatedDate': '2013-01-20T00:00:00Z',
  'Roles': [
    'User',
    'Admin'
  ]
}";

// Deserialize it (the example)
Account account = JsonConvert.DeserializeObject<Account>(json);

// Output the result [in this case we're testing the email of the account].
Console.WriteLine(account.Email);
Posted by: Guest on August-24-2021

Code answers related to "c# deserialize object / class newtonsoft"

C# Answers by Framework

Browse Popular Code Answers by Language