I am trying to change the JSON from a JSON file so I can run it to get a JSON response, I found the code on this post: Change values in JSON file (writing files) can anyone fix this?
Error:
An unhandled exception of type 'System.ArgumentException' occurred in Newtonsoft.Json.dll
Additional information: Set JArray values with invalid key value: "filter". Int32 array index expected.
JSON:
[{
"tablename" : "table",
"columns" : "id, name",
"filter" : "id = 10"
}]
Code:
string json = File.ReadAllText("file.json");
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
jsonObj["filter"] = "id = 20";
string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText("file.json", output);
(The JSON is made to talk to a webservice)