HI all,
Existing JSon File Contains and File Saved as UniqueID.JSON
{
UniqueID :1123,
Datetime:"",
User:"",
}
And I need to read the file and append the courses (It's List) taken by the user into Existing Json File.Please help me
Expected output
{
UniqueID :1123,
Datetime:"",
User:"",
Courses:[
{
name : English
},
{
name : Maths
},
]
}
Rajkiran SwainPosted Jun 26, 2023, 2:44 PM
Try this.
Amit MohantyPosted Jun 27, 2023, 5:29 AM
Hey, if you're getting a NullReferenceException when trying to add the courses to data.Courses, it means that the Courses property is null. You need to initialize it with a new instance of List before adding items to it.
Rajkiran SwainPosted Jun 27, 2023, 5:02 AM
DrtPosted Jun 27, 2023, 12:46 AM
Hi!!
var courses = new List { new Course { Name = "English" }, new Course { Name = "Maths" } }; If i want to add the courses through dynamically how should i append into courses. Trying to Append but it replace the old content but not new course is not appending
DrtPosted Jun 26, 2023, 1:53 PM
Hi Amit
data.Courses.AddRange(courses);
While adding am getting System.NullReferenceException: 'Object reference not set to an instance of an object.' but when i debug having data .
Amit MohantyPosted Jun 26, 2023, 9:17 AM
Check this: