I have a JSON string with Multiple JSON Object. I would like to know how to deserialize Json string to DataSet.
I have deserialize JSON string to DataTable. It works fine but I would like to know how to convert multiple JSON object to dataset
Below is sample JSON:
{
"Name": "Jamal",
"Age": "42",
"City": "Mumbai",
"EducationalInfo": [{
"Degree": "BE",
"University": "Cristian Universiy"
}, {
"Degree": "ME",
"University": "Texas University"
}],
"LoanInfo": [{
"LoanType": "Car Loan",
"Amount": "1000000"
}, {
"LoanType": "Personal",
"Amount": "200000"
}]
}
Expected Output is:
Name, Age, City is one datatable
Degree & University is one datatable
LoanType & Amount is one datatable
Please suggest how to covert this.
2
Answers
First, you want to create a model to deserialize your JSON string. In your case, your model would look as follow:
Then you can deserialize it by doing the following:
Where
root
will be your object filled with the content of the JSON string.To convert the given JSON string into a DataSet with multiple DataTables, you can utilize the Newtonsoft.Json library in C#.
Use below class to deserialize the JSON string.
Rootobject rootobject = JsonConvert.DeserializeObject(jsonString);