I have the following JSON file (list.json):
[
{
"groupID": "12345",
"subID": "71",
"stock": false,
"price": "32.21"
},
{
"groupID": "12345",
"subID": "25",
"stock": false,
"price": "12.94"
}
]
What a I like to do is, that I edit the "stock" value of one specific object. So if the value of stock is false I like to change it to true and if its true I like to change to false.
I tried to start but I have already at the beginning a big problem. I get already while the parsing a Newtonsoft.Json.JsonReaderException : 'Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.'. I believe it happens because the JSON starts with an array.
My method:
public void EditJSON (string GroupID, string SubID)
{
JObject JSONnew = JObject.Parse(list.json);
if (*stock is true*)
{
*change stock to false*
}
if (*stock is false*)
{
*change stock to ture*
}
}
How I can find in the JSON the correct object by using the GroupID and the SubID and edit the value of stock from false to true or the opposit?