I am lacking one element so far, but if you have managed to excavate the menu.json file into a string, this should give you all you need to proceed.
These Class definitions should suffice:
Code:
class ClassNavRoot dim children() as EventType ' EVENT_TYPE dim id as string ' = "0" on ROOT dim name as string ' = "ROOT" dim type as string ' = "GROUP" end class class ClassNavEventType dim children() as Object ' GROUP or EVENT or RACE dim id as string ' Betfair EventTypeId dim name as string ' = name of sport dim type as string ' = "EVENT_TYPE" end class Class ClassNavGroup dim children() as Object ' GROUP or EVENT dim id as string ' Other Number - unique but otherwise not meaningful dim name as string ' = group name dim type as string ' = "GROUP" end class Class ClassNavEvent dim children() as Object ' GROUP or MARKET or EVENT dim id as string ' Betfair EventId dim name as string ' = name of event dim countryCode as string ' 2-character code dim type as string ' = "EVENT" end class Class ClassNavRace ' For Horse Racing of Greyhounds only dim children() as Object ' MARKET dim id as string ' Betfair RaceId dim name as string ' = distance as text, probably dim startTime as datetime ' (or string?) eg "2014-08-12T11:15:00.000Z" dim type as string ' = "RACE" dim venue as string dim raceNumber as string ' US specific eg "R1" dim countryCode as string ' 2-character code end Class Class ClassNavMarket dim exchangeId as string ' = "1" usually dim id as string ' Betfair marketID dim marketStartTime as dateTime dim marketType as string ' eg WIN, PLACE, etc dim numberOfWinners as string ' (or numeric, but PDF example is in quotes) dim name as string ' eg "Match Odds" dim type as string ' eg "MARKET" end class
https://api.betfair.com/exchange/bet...tion/menu.json
In plain English:
A ROOT group node has one or many EVENT_TYPE nodes
An EVENT_TYPE node has zero, one or many GROUP nodes
An EVENT_TYPE node has zero, one or many EVENT nodes
A Horse Racing EVENT_TYPE node has zero, one or many RACE nodes
A RACE node has one or many MARKET nodes
A GROUP node has zero, one or many EVENT nodes
A GROUP node has zero, one or many GROUP nodes
An EVENT node has zero, one or many MARKET nodes
An EVENT node has zero, one or many GROUP nodes
An EVENT node has zero, one or many EVENT nodes
https://api.developer.betfair.com/se...r+Applications
NOTES
I've added "Nav" into the class names to denote that they relate to the navigation file data.
The data hierarchy begins with the ROOT which contains an array of EVENT_TYPEs. EVENT_TYPEs each have an array of GROUP or EVENT or RACE items.
The GROUP items are the kind that appear on the Betfair menu as SATURDAY GAMES or DIVISION 3 or EUROPEAN CUP or THE ASHES SERIES or whatever.
When navigating the data, the type will always tell you what type of item you are dealing with. This is just as well, because the Class items for EVENT_TYPE and GROUP are identical and I expect the deserialiser to mix these up, so checking the class/object type wouldn't work. It's just as well, then, that the type string is there.
Because some of the children arrays - in the EVENT_TYPE and GROUP classes - can contain different types of data, they had to be defined as the unspecific OBJECT rather than a more specific class. The ROOT class is essentially the same too, except that its array always contains EVENT_TYPE data.
I have coded the children() as arrays, but they could also be collections in VB.NET and, I expect, other data structures in other languages.
Any set of items should end in a Market item, unless the sport in question is intermittent in nature, in which case you might encounter an empty children() array. Expect this.
I would guess - and I may be wrong - that the navigation file is altered on a daily basis.
I do want to include code for retrieving the menu.json file from Betfair, but it will have to wait until I can persuade mine to behave.
DESERIALISING
If you get to the point where you have the entire menu.json file existing as a string, with the classes from above in your program, it is fairly simple to turn it into an object.
This is what I've been using; another apology - this time to whoever originally coded it as I can't give them a name check owing to the mists of time.
I have this line at the top of my project:
Code:
Imports System.Web.Script.Serialization
Code:
Dim jss As New JavaScriptSerializer() 'JSON serialiser yourObject = jss.Deserialize(Of ClassofYourObject)(yourJSONString)
Code:
aJSONString = jss.Serialize(anObject)
Being specific to our current task, this will turn your menu.json string into a convenient object:
Code:
Dim jss As New JavaScriptSerializer() 'JSON serialiser Dim navData as ClassNavRoot = jss.Deserialize(Of ClassNavRoot)(yourMENUdotJSONString)
* * * *
If you spot any glaring errors, please let me know and I'll correct the text in this post so that the future lost folk don't have to hunt around for corrections.



which you seem to be pretty hot on Jabe.
Leave a comment: