Ad

How Can I Get Auto Generated Id From JSON In ReactJS Or C#

- 1 answer

how can i get auto generated id from this object in an array thank you

{
    "CourseList": {
        "-Lti4CFDdJwAkBW5ujqm": {  //auto generated id
            "a1_courseName": "robotics",
            "a2_courseCode": "1212"
        },
        "-LtrpJSDN4OCQAyJiSmQ": {  //auto generated id
            "a1_courseName": "shsh",
            "a2_courseCode": "hhshs"
        }
    },
    "PersonalInfo": {
        "email": "[email protected]******.edu",
        "teacherInstitute": "####",
        "teacherName": "arif"
    }
}
Ad

Answer

I have tested with NewtonSoft Json, generate it as Dictionary,

public partial class CourseAndnfo
{
   public Dictionary<string, CourseList> CourseList { get; set; }
    public PersonalInfo PersonalInfo { get; set; }
}

public partial class CourseList
{
    public string a1_courseName { get; set; }
    public string a2_courseCode { get; set; }
}

public partial class PersonalInfo
{
    public string Email { get; set; }
    public string TeacherInstitute { get; set; }
    public string TeacherName { get; set; }
}

Deserialize it using,

var ParsedJson = JsonConvert.DeserializeObject<CourseAndInfo>(Yourjson);
List<string> AutoGeneratedIds = ParsedJson.CourseList.Keys.ToList();
Ad
source: stackoverflow.com
Ad