Best methodology for handling Json SSE event data?
Hi Guys,
I am playing around with SSE and am receiving data in Json format. (I don't have control over the server and have to deal with whatever comes my way.)
I am currently detecting the type of event and handling the data but it feels like I have created clunky code that is somewhat unreliable in properly determining the type of event data that I am receiving.
For example, I have 8 events types
Start Event, End Event, BigAction Event, SmallAction Event, Time Event, Message Event, Outcome Event, Status Event
What I am finding is that I receive a lot of Time Events and they are often immediately after a BigAction or SmallAction or Status Event which is causing me to miss the important information in these events.
What I am hoping, is that someone might have a methodology or preferred way of handling and parsing the Json data so that I can process the events sequentially and avoid missing important information.
I am not wanting to pre-empt a solution by providing the code I have as it's pretty bad. I am an amateur doing this for the fun and challenge and am wanting to learn the best way to handle Json data .
I
Code:
Dim LiveData as String = JObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of JObject)(LiveDataStream)
Then I
Code:
Dim DataType as String = LiveData("datatype").ToString
And from there I can work with the data.
I feel as though I am not handling the initial receipt of data correctly.
I am using
Code:
If Line.StartsWith("BigAction") then
LiveData = Line.Substring(9).trim()
ParseBigActionJson()
End If
And I have one of these for each of the event types I am expecting
When I use the Test Data (an event every 10 seconds) that comes from the server, all the code works correctly but when I switch to the live data stream(event intervals vary tremendously, with my code handling the events when there is a time gap between them but fails when the events come in rapid succession) then I don't get the results I expect because my code seems to miss identifying the event type
I feel that I am missing something really fundamental and I am really looking forward to learning how best to handle the initial processing and identifying of the incoming event.
Regards,
Antony.