Reputation: 2755
I have a File with following formatted Json
{
"Id": 0,
"MsgId": 125,
"ExceptionDetails": "whatever2"
}
{
"Id": 1,
"MsgId": 135,
"ExceptionDetails": "whatever2"
}
This is exactly how it is in a file with no brackets.
I need to parse this text file and get the values of these Keys, for instance in this example I need to get the 0 and 1
Thanks
and this is how it is getting written to the file, so probably Im not writting to the file in correct JSON FORMAT
string json = JsonConvert.SerializeObject(logs, Formatting.Indented);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\development\commonArea\WriteLines.txt", true))
{
file.WriteLine(json);
}
Upvotes: 0
Views: 305
Reputation: 64
var x = [{
"Id": 0,
"MsgId": 125,
"ExceptionDetails": "whatever2"
},
{
"Id": 1,
"MsgId": 135,
"ExceptionDetails": "whatever2"
}]
x[0].Id // 0
x[1].Id // 1
Upvotes: 0
Reputation: 1601
Is that your raw file? If so, it's not valid json.
What you can do in your case is to use string splitting or regex-fu to split your file into separate json objects and then parse them using either the built-in JavaScriptSerializer or Newtonsoft.Json.
Upvotes: 1