I'm trying to consume some JSON files, which could contains a arbitrary number of child values.
By simplifying the JSON, I get something like:
{
"timestamp":1710415627927,
"parent":{
"id":"680867",
"key":"XXX",
"childs":{
"customchild_1":{
"value":"DIS",
"id":"16805"
},
"customchild_2":null,
"customchild_3":null,
"customchild_4":[
"01 (CHIL-172)"
],
"customchild_5":[
"02 (CHIL-44553)"
],
"customchild_6":{
"value":"Achievement",
"id":"13425",
}
}
}
}
Of course, each file could have different number of customfield_xxx attributes, and values associated can be (generally) above 3 kind of values (id / value, [] or null)
I try to create a first class for parent
public class parent
{
public Dictionary<object, List<customchild>> customchilds { get; set; }
...
}
public class customchild
{
public string value { get; set; }
public string id { get; set; }
}
problem is that I don't know if it will work for all and on my main process, how I can :
- count the number of customchild attributes in my JSON
- access the Nth customchild ?
Utilize the Newtonsoft.Json Nuget Package to deserialize JSON as a parent object. From there, you can access the count of custom child attributes using
parentObject.ParentDetails.Customchilds.Count.It's functioning smoothly in my compiler.