Announcement

Collapse
No announcement yet.

Fields not being returned

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fields not being returned

    Hi, having just started with the Betfair API, I have managed to return the Market Catalogue and extract several elements as per below but cannot extract a runnerName or sortPriority. Can anyone help with what I may be doing wrong with these two elements? Cheers.

    List Market Catalouge =

    {"jsonrpc":"2.0","result":[{"marketId":"1.221211822","marketName":"R6 1730m Pace M","totalMatched":25185.597528000002,"runners":[{"selectionId":62688924,"runnerName":"1. Shez A Punter","handicap":0.0,"sortPriority":1},{"selecti onId":62437153,"runnerName":"3. Jets Reason","handicap":0.0,"sortPriority":2},{"selecti onId":62688927,"runnerName":"5. Sheza Lenny","handicap":0.0,"sortPriority":3},{"selectio nId":62688928,"runnerName":"6. Dreamtime Nala","handicap":0.0,"sortPriority":4},{"selection Id":60579782,"runnerName":"7. Santuzza Art","handicap":0.0,"sortPriority":5},{"selection I d":62688929,"runnerName":"8. Fay Irene","handicap":0.0,"sortPriority":6},{"selectio nId":62688930,"runnerName":"9. Shes Perfection","handicap":0.0,"sortPriority":7},{"sel ectionId":62688931,"runnerName":"10. Millwood Brooklyn","handicap":0.0,"sortPriority":8},{"selec tionId":62688926,"runnerName":"4. Major Ark","handicap":0.0,"sortPriority":9},{"selection I d":62688925,"runnerName":"2. Studleigh Anne","handicap":0.0,"sortPriority":10}]}],"id":1}

    Response.Item(1).Item("marketId")
    Output: MarketId = 1.221211822

    Response.Item(1).Item("marketName")
    Output: Market Name = R6 1730m Pace M

    Response.Item(1).Item("totalMatched")
    Output: Total Matched = 25185.597528

    Dim Runners As Object: Set Runners = Response.Item(1).Item("runners")
    GetSelectionIdFromMarketBook = Runners.Item(1).Item("selectionId")
    Output: Selection Id (1) = 62688924

    Dim Runners As Object: Set Runners = Response.Item(1).Item("runners")
    GetRunnerNameFromMarketBook = Runners.Item(1).Item("runnerName")
    Output: Runner Name (1) =

    Dim Runners As Object: Set Runners = Response.Item(1).Item("runners")
    GetHandicapFromMarketBook = Runners.Item(1).Item("handicap")
    Output: Handicap (1) = 0

    Dim Runners As Object: Set Runners = Response.Item(1).Item("runners")
    GetSortPriorityFromMarketBook = Runners.Item(1).Item("sortPriority")
    Output: sortPriority (1) =

  • #2
    I am not really a VB programmers so take this with a large pinch of salt but .......

    Your code as shown here will soon become too unwieldy to follow as you are having to manually figure out where every item of data is with lines like
    Dim Runners As Object: Set Runners = Response.Item(1).Item("runners")​
    the multiple items reference gets confusing.

    A better approach is just throw that that json string at newtonsofts json parser to convert it into a VB data structure for you
    The JSON string you posted is valid, you can visualise it nicely if you paste it into https://jsonviewer.stack.hu/

    A Deserialise code example is shown below, if you cant follow it or it is wrong shoot Chat GPT not me

    Code:
    Imports Newtonsoft.Json
    
    ' Define your data structure
    Public Class MyData
        Public Property Property1 As String
        Public Property Property2 As Integer
    End Class
    
    ' Your JSON string
    Dim jsonString As String = "{""Property1"":""Value1"", ""Property2"":123}"
    
    ' Deserialize the JSON string into your data structure
    Dim data As MyData = JsonConvert.DeserializeObject(Of MyData)(jsonString)
    
    ​

    Comment


    • #3
      Thanks Geoff you are correct, it is becoming unwieldy already, I will look at refactoring the code similar to the approach you have exampled. The issue I had was in the JSON Parser code so I have updated that and was able to return the missing data correctly.

      Comment

      Working...
      X