public
Created

Prepare data for unittests. Deserialize JSON to object hierarchy. Take from http://stackoverflow.com/a/9988494/443366

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
void Main()
{
JsonConvert.DeserializeObject<Root>(testJson).Dump();
}
 
readonly string testJson =
"{\"Profile\": [{" +
" \"Name\":\"Joe\"," +
" \"Last\":\"Doe\"," +
" \"Client\":" +
" {" +
" \"ClientId\":\"1\"," +
" \"Product\":\"Apple\"," +
" \"Message\":\"Peter likes apples\"" +
" }," +
" \"Date\":\"2012-02-14\"" +
" }]" +
"}";
 
public class Root
{
public Profile[] Profile;
}
 
public class Profile
{
public string Name { get; set; }
public string Last { get; set; }
public Client Client { get; set; }
public DateTime Date { get; set; }
}
 
public class Client
{
public int ClientId;
public string Product;
public string Message;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.