I wanted to analyze Telegram-Chats so I exported a chat in JSON format and wanted to deserialize it into my analyzing software.
{
"id": 397910,
"type": "message",
"date": "2018-02-21T10:27:59",
"edited": "1970-01-01T01:00:00",
"from": "Username",
"from_id": 39033284,
"text": "Some Text"
}
So I've used this simple code to read the JSON
List<JSONObject> jsonObjects = JsonConvert.DeserializeObject<List<JSONObject>>(File.ReadAllText(openFileDialog.FileName));
public class JSONObject
{
public int ID;
public string type;
public string date;
public string edited;
public string from;
public int fromID;
public string photo;
public int width;
public int height;
public string text;
}
This went very well for the first 525 datasets but afterwards, I had trouble deserializing the data because of "consistency issues". The Datatype of the text sometimes changes to an array.
{
"id": 397911,
"type": "message",
"date": "2018-02-21T10:31:47",
"edited": "1970-01-01T01:00:00",
"from": "Username",
"from_id": 272964614,
"text": [
"Some Text ",
{
"type": "mention",
"text": "@school"
},
" Some Text"
]
}
Also, I found this dataset
{
"id": 397904,
"type": "message",
"date": "2018-02-21T10:18:12",
"edited": "1970-01-01T01:00:00",
"from": "Username",
"from_id": 39033284,
"text": [
{
"type": "link",
"text": "google.com"
},
"\n\nSome Text"
]
}
I don't know how I deserialize the data when it shows this kind of inconsistency.