Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Created January 8, 2013 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/4483835 to your computer and use it in GitHub Desktop.
Save akimboyko/4483835 to your computer and use it in GitHub Desktop.
Prepare data for unittests. Deserialize JSON to object hierarchy. Take from http://stackoverflow.com/a/9988494/443366
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment