public class Student
{
public string Name { get; set;} = "ABCD";
public List<Subject> Subjects {get; set;}
public Student()
{
Subjects = new List<Subject>();
SetDefaultSubject();
}
private void SetDefaultSubject()
{
this.Subjects.Add(new Subject(){Name = "English"});
this.Subjects.Add(new Subject(){Name = "Maths"});
}
}
public class Subject
{
public string Name {get; set;}
}
I have a Json String which look like this
var jsonStudentData = @"{""Name"":""ABC"",""Subjects"":[{""Name"":""English""},{""Name"":""Maths""},{""Name"":""Hindi""},{""Name"":""Social Studies""}]}";
This is my code where i am deserialising jsonStudentData
JsonConvert.DeserializeObject<Student>(jsonStudentData);
I am getting the Output
Name = ABC,
Subject [English,Maths,English,Maths,Hindi,Social Studies]
but i want Output
Name = ABC, Subject [English,Maths,Hindi,Social Studies]
Am i Doing Wrong anything here.