I'm attempting to read the contents of a JSON file using Newtonsoft JSON which is a list of dictionaries, iterate through them, and create a new list of dictionaries after rooting out the one I don't want which will eventually be written back to the JSON file.
No matter what I try, I can't seem to be able to add the JSON entries within its list back to a new List. Here's the error:
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
The best overloaded method match for 'System.Collections.Generic.List<System.Collections.Specialized.OrderedDictionary>.Add(System.Collections.Specialized.OrderedDictionary)'
has some invalid arguments
Here's the JSON string I've deserialized:
[
{
"name":"test",
"custom":false,
"file":"strawberry-perl-5.10.1.2portable.zip",
"url":"http://strawberryperl/....",
"ver":"5.10.1",
"csum":"f86ae4b14daf0b1162d2c4c90a9d22e4c2452a98"
}
]
And here's my code:
dynamic customPerlList = JsonParse("perls_custom");
List<dynamic> updatedList = new List<dynamic>();
foreach (var perlStruct in customPerlList)
{
if (perlStruct.name != perlVersionToRemove)
{
Console.WriteLine("match");
updatedList.Add((OrderedDictionary)perlStruct);
}
}
I've just started developing in C#, so my attempts using examples found while searching either aren't sinking in, or I'm missing something else. Can someone please point out the err in my ways, and what the proper approach is to do what I'm attempting?