Question Json string

siji

New member
Joined
Jun 26, 2022
Messages
1
Programming Experience
3-5
Dear Team,

Please help to get the following json string using C# code.
C#:
{
    "records": {
        "record": [
            {
                "employee": 151,
                "account": "aaa",
                "department": "ss"
            },
            {
                "employee": 152,
                "account": "bbb",
                "department": "yy"
            }
        ]
    }
}
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,469
Location
Chesapeake, VA
Programming Experience
10+
First we are not part of your team. Or is this salutation that is standard in your country?

Next, we are not a code writing service. We won't do your work for you even if we were part of your team

Please show us what you have done so far. Tell us what problems you are encountering. We can try to help you by guiding you towards a solution.
 

Saravanan S

New member
Joined
Jun 17, 2022
Messages
1
Programming Experience
5-10
It would be something like below

C#:
public class Record
{
    public int employee { get; set; }
    public string account { get; set; }
    public string department { get; set; }
}

public class Records
{
    public List<Record> record { get; set; }
}

public class Root
{
    public Records records { get; set; }
}
 
Last edited by a moderator:

cjard

Member
Joined
Jan 25, 2012
Messages
17
Programming Experience
10+
It would be something like below

C#:
public class Record
{
    public int employee { get; set; }
    ...
}
You don't need to violate C# naming conventions just to get the JSON to turn out with camelCase names; use the relevant attribute of your JSON serializer (e.g. [JsonProperty("employee")] public int Employee {get;set;} - NewtonSoft) to dictate the json name independently of the C#
 
Top Bottom