I am sending the Json format like this in PostMan
{
"number": 2106887,
"date": "09/10/2018",
"degree":"BE"
"Students": [
{
"Branch": "ABK015",
"Doc": "NCE",
"Description": "Testing",
"dni": "1016035232",
"Name": "ABCE",
"Gender": "M",
"Title": "Univercity",
"email": "[email protected]",
},
{
"Branch": "ABK016",
"Doc": "NCE",
"Description": "Testing1",
"dni": "1016035233",
"Name": "ABCE",
"Gender": "M",
"Title": "Univercity",
"email": "[email protected]",
}
]
}
In controller level i am doing the validation of all fields. After validation how can i convert the above json string to below format
{
"Students": [
{
"number": 2106887,
"date": "09/10/2018",
"degree":"BE"
"Branch": "ABK015",
"Doc": "NCE",
"Description": "Testing",
"dni": "1016035232",
"Name": "ABCE",
"Gender": "M",
"Title": "Univercity",
"email": "[email protected]",
},
{
"number": 2106887,
"date": "09/10/2018",
"degree":"BE"
"Branch": "ABK016",
"Doc": "NCE",
"Description": "Testing1",
"dni": "1016035233",
"Name": "ABCE",
"Gender": "M",
"Title": "Univercity",
"email": "[email protected]",
}
]
}
And aftre converting, i want to insert to database. How to convert in c#? Please help me.
And the below code is the class for students:
public class Students
{
[Required]
public string Branch{ get; set; }
[Required]
public string Doc{ get; set; }
[Required]
public string Description{ get; set; }
[Required]
public string dni{ get; set; }
[Required]
public string Name{ get; set; }
[Required]
public string Gender{ get; set; }
[Required]
public string Title{ get; set; }
[Required]
public string email{ get; set; }
[Required]
public string degree{ get; set; }
[Required]
public string date{ get; set; }
[Required]
public string number{ get; set; }
}
And i am deserializing here
var requestBody = requestContent.Content.ReadAsStringAsync().Result;
JObject jxxx = JsonConvert.DeserializeObject<dynamic>(requestBody);
Please refer the updated code
var requestBody = requestContent.Content.ReadAsStringAsync().Result; JObject jxxx = JsonConvert.DeserializeObject<dynamic>(requestBody);here the requestContent is json format