Property Settings
Attributes/Decorators
Class Settings
List Settings
Make sure that the JSON string is well formatted. The JSON object should be wrapped with curly braces and should not be escaped by backslashes.
Example JSON:
{
"Class1":{
"id":4,
"user_id":"user_id_value",
"awesomeobject":{
"SomeProps1":1,
"SomeProps2":"test"
},
"created_at":"2015-06-02 23:33:90",
"updated_at":"2015-06-02 23:33:90",
"users":[
{
"id":"6",
"name":"Test Child 1",
"created_at":"2015-06-02 23:33:90",
"updated_at":"2015-06-02 23:33:90",
"email":"test@gmail.com"
},
{
"id":"6",
"name":"Test Child 1",
"created_at":"2015-06-02 23:33:90",
"updated_at":"2015-06-02 23:33:90",
"email":"test@gmail.com",
"testanadditionalfield":"tet"
} ]
},
"Class2":{
"SomePropertyOfClass2":"SomeValueOfClass2"
}
}
Click the convert button and wait a few seconds until your C# classes appear.
When you copy the returned classes in the directory of your solution, you can deserialize your JSON response using the 'Root' class using any deserializer like Newtonsoft.
This is the response you'll get from the JSON request we made earlier:
public class Awesomeobject {
public int SomeProps1 { get; set; }
public string SomeProps2 { get; set; }
}
public class User {
public string id { get; set; }
public string name { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public string email { get; set; }
public string testanadditionalfield { get; set; }
}
public class Class1 {
public int id { get; set; }
public string user_id { get; set; }
public Awesomeobject awesomeobject { get; set; }
public string created_at { get; set; }
public string updated_at { get; set; }
public List users { get; set; }
}
public class Class2 {
public string SomePropertyOfClass2 { get; set; }
}
public class Root {
public Class1 Class1 { get; set; }
public Class2 Class2 { get; set; }
}
And this is how you deserialize it in your C# code:
Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);