I would like to add a object to a null field
I have a json file "FileXXX" which has some variables and a collection "SomeList".
This "SomeList" has a collection "Group" of its own, in which i whant to insert a collection like seen in the second entry of "SomeList".
{
"Name": "some name",
"Jear": 2021,
"SomeList": [
{
"ID": "XXXXXX",
"Something": "",
"Something else": 0,
"...": 0,
"Group": null
},
{
"ID": "YYYYYY",
"Something": "",
"Something else": 0,
"...": 0,
"Group": [
{
"Something": "",
"Something else": 0
}
]
},
... x entrys
]
}
I am not using the NullValueHandling.Ignore because i am using the null value as a variable, if the "Group" information should be displayed.
What i did until now, is to create a complete new json file, paste the old data into it, add the group at the specific entry and overwrite the old json file.
So basicly i am looking for the code below without the null exception popping up.
if (FileXXX.Somelist[0].Group == null)
{
FileXXX.Somelist[0].Group.Add(myGroupObject);
}
is there simple way to achieve this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…