I am trying to read a local .json file using StreamReader
:
My code:
using (var jsonReader = new StreamReader(pathToMyJsonFile))
{
string json = jsonReader.ReadToEnd();
dynamic array = JsonConvert.DeserializeObject(json);
foreach (var item in array)
{
Console.WriteLine(item.fuzzy);
}
}
My json:
[
{
"fuzzy": "12345",
"name": "{jon-errand}",
"email": "person@gmail.com",
"lights": "red",
"friends": "Elizabeth",
"traits": {
"Hair": "brown",
"Eyes": "yellow"
}
}
]
I get the exception: Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject.
I have tried looking at the SO answer posted here but I am sure my json is a real array. Without changing the above json, how can I read this json file in a useful way so I can pull out specific fields? Such as getting the email
field as person@gmail.com
?