0

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;}
}

enter image description here

Lazytitan
  • 47
  • 1
  • 11
  • Also, does your current code not work? If so, where and how is it failing? – dbc Mar 21 '23 at 07:05
  • @dbc : I put in my code but Serge's answer solved it for me. Thanks again for looking and me and showing the right way to ask questions here. Thank you. – Lazytitan Mar 21 '23 at 20:10

1 Answers1

1

try

MessageBox.Show("First name: " + student.Name.FirstName);
MessageBox.Show("Last name: " + student.Name.LastName);
Serge
  • 40,935
  • 4
  • 18
  • 45