Created
January 8, 2013 13:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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