I'm trying a class to read from a JSON string using JsonTextReader (i need to read in a streaming pov, without loading the whole structure into memory). But it seems that JsonTextReader does not work well with arrays or I'm doing something wrong, since there are values that are not Read().
My code:
while (jsonReader.Read())
{
if (jsonReader.Value != null)
Console.WriteLine("Token: {0}, Value: {1}", jsonReader.TokenType, jsonReader.Value);
else
Console.WriteLine("Token: {0}", jsonReader.TokenType);
}
My JSON file:
{
"employees": [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones"
}
]
}
The output:
Token: StartObject
Token: StartArray
Token: StartObject
Token: PropertyName, Value: firstName
Token: PropertyName, Value: lastName
Token: EndObject
Token: StartObject
Token: PropertyName, Value: firstName
Token: PropertyName, Value: lastName
Token: EndObject
Token: StartObject
Token: PropertyName, Value: firstName
Token: PropertyName, Value: lastName
Token: EndObject
Token: EndArray
Token: EndObject
Please note that the content like Jonh, Anna, Doe,... aren't showed.
Any idea how could I solve this? I'm avoiding serialization\deserialization solutions or LINQ, since I can't load the whole structure into memory.
Thanks