I think I ran into this one in the past but I don't recall.
I am trying to figure out a way to keep proper JSON output order, like so:
{"ClockMinutes":15,"ClockSeconds":0,"ClockMilliseconds":0,"HomeScore":0,"GuestScore":0,"Inning":1,"Ball":0,"Strike":0,"Out":0}
My routine looks like this:
But it does not maintain the same order as the above JSON which causes me issues down the line.
any thoughts on how to fix this? thanks
I am trying to figure out a way to keep proper JSON output order, like so:
{"ClockMinutes":15,"ClockSeconds":0,"ClockMilliseconds":0,"HomeScore":0,"GuestScore":0,"Inning":1,"Ball":0,"Strike":0,"Out":0}
My routine looks like this:
B4X:
'Sends all scoreboard data to the HMI over the ScoreData topic.
Sub RefreshDataToHMI(Targetaddress As Int)
Dim Response As Map
Dim JSON As JSONGenerator
Response.Initialize
'Put Scoreboard scorekeeping data into JSON Map
Dim ScoreData As Map = Main.Scorekeepers(Targetaddress).GetScoreData
Dim Baseball As BaseballScoreData = ScoreData.Get("Baseball")
Dim GameClock As GameClockData = ScoreData.Get("GameClock")
Response.Put("ClockMinutes", GameClock.Minutes)
Response.Put("ClockSeconds", GameClock.Seconds)
Response.Put("ClockMilliseconds", GameClock.Milliseconds)
Response.Put("HomeScore", Baseball.Home)
Response.Put("GuestScore", Baseball.Guest)
Response.Put("Inning", Baseball.Inning)
Response.Put("Ball", Baseball.Ball)
Response.Put("Strike", Baseball.Strike)
Response.Put("Out", Baseball.Out)
JSON.Initialize(Response) 'Build the JSON Object
Dim JSONResponse As String = JSON.ToString 'Save it into a string
If mqtt.Connected = True Then mqtt.Publish("ScoreData/" & Targetaddress, JSONResponse.GetBytes("UTF-8")) 'Send JSON String to HMI
End Sub
But it does not maintain the same order as the above JSON which causes me issues down the line.
any thoughts on how to fix this? thanks