I have some json that looks like this:
"lines":
{
"0010": {
"ProvCountyCode": "047",
"ProvNo": "770887",
"ParNonparCode": "K",
"ParNonparCode2": "K",
},
"0020" {
"ProvCountyCode": "047",
"ProvNo": "0888",
"ParNonparCode": "K",
"ParNonparCode2": "K",
},
...
Visual Studio (C#) "Paste Special / Classes from JSON" creates something like this:
public class Lines
{
public _0010 _0010 { get; set; }
public _0020 _0020 { get; set; }
}
public class _0010
{
public string ProvCountyCode { get; set; }
public string ProvNo { get; set; }
public string ParNonparCode { get; set; }
public string ParNonparCode2 { get; set; }
}
public class _0020
{
public string ProvCountyCode { get; set; }
public string ProvNo { get; set; }
public string ParNonparCode { get; set; }
public string ParNonparCode2 { get; set; }
}
// ...
This doesn't look very useful to me. Further down, there is a json array called lineSummary that includes a value LineID.
I am thinking I want to reference the dictionary like this:
Lines[LineId]
I can't change the JSON. I am looking to create a class that accomodates it
public class public class Lines { public Dictionary<string, Line> lines { get; set; } = new(); }. The property names (here"0010"and"0020") will become the keys. Works with both System.Text.Json and Newtonsoft.