I am trying to deserialize complex nested JSON in Script Component SSIS WITHOUT using newtonsoft. This is how far I have reached. Thanks for any help.
Deserialize complete JSON
Example of my JSON file:
[{ "studentId":A2336, '"Name":{ "FirstName":"John", "LastName":"Doe"} } { "studentId":B1470, '"Name":{ "FirstName":"Mary", "LastName":"Smith"} } ]
//current code
Public override void CreateNewOutputRows()
{
String jsonFileContent = File.ReadAllText(@"C:\desktop\sample.json");
javaScriptSerializer js = new javaScriptSerializer();
List<Student> allStudents = js.Deserialize<List<Student>>(jsonFileContent);
foreach(var student in allStudents)
{
Output0Buffer.AddRow();
System.Windows.Forms.MessageBox.Show("Student Id is: " + student.studentId.ToString());
//how to print the first and last name
}
}
Class Student
{
Public String studentId { get; set;}
Public Name Name get; set;}
}
Class Name
{
Public String FirstName { get; set;}
Public String LastName { get; set;}
}
try
MessageBox.Show("First name: " + student.Name.FirstName);
MessageBox.Show("Last name: " + student.Name.LastName);