Convert a JavaScript object or array to JSON format with this simple online JavaScript to JSON converter tool... xem thêm
Step 1 : Copy the JSON body inside the first code editor
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"
}
}
Step 2 : Click Convert in order to start generating C# classes.
Click the convert button and wait a few seconds until your C# classes appear.
Step 3 : Copy the retuned C# classes from the second editor and deserialize using the 'Root' class.
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; }
}