I'm new to C# and I want to read a .log
file with json entries like this:
{
"firstName": "John", "lastName": "Smith"
}
{
"firstName": "Alice",
"lastName": "Smith"
}
I want to parse from "{" to "}" to get the beginning and end of one entry.
I used:
StreamReader sr = new StreamReader(FileName);
logfile = sr.ReadLine();
var logentry = JsonConvert.DeserializeObject<dynamic>(logfile);
to deserialize the entry. It works well if the json entry is in one line. But the problem is that with ReadLine()
, I can only read the json format in one line not multiple like the second example.
Maybe I could use ReadToEnd()
and save it in a string and count the "{" and "}" and separate the entries.