Accessing the JSON part of this HTTP response

I have used the code provided here (link to Stackoverflow) to access the Betfair API. And things work; a response is obtained. However, I would now like to use the data that I have retrieved, and that is what I cannot figure out how to do.

I get the following HTTP response, which clearly contains a JSON part. The data is contained in “ListEventTypesResponse” (see the link for the code):

HTTP.Messages.Response:

“”"
HTTP/1.1 200 OK
Date: Fri, 05 Jun 2020 11:16:47 GMT
Cache-Control: no-cache
Content-Type: application/json
Vary: Accept-Encoding, User-Agent
Content-Length: 1722
Content-Security-Policy-Report-Only: default-src ‘unsafe-inline’ ‘unsafe-eval’ data: https: wss:; report-uri https://shk.betfair.com/csp
X-XSS-Protection: 1; mode=block

{“jsonrpc”:“2.0”,“result”:[{“eventType”:{“id”:“1”,“name”:“Soccer”},“marketCount”:4112},{“eventType”:{“id”:“2”,“name”:“Tennis”},“marketCount”:130},{“eventType”:{“id”:“3”,“name”:“Golf”},“marketCount”:8},{“eventType”:{“id”:“4”,“name”:“Cricket”},“marketCount”:12},{“eventType”:{“id”:“5”,“name”:“Rugby Union”},“marketCount”:22},{“eventType”:{“id”:“1477”,“name”:“Rugby League”},“marketCount”:69},{“eventType”:{“id”:“6”,“name”:“Boxing”},“marketCount”:18},{“eventType”:{“id”:“7”,“name”:“Horse Racing”},“marketCount”:654},{“eventType”:{“id”:“8”,“name”:“Motor Sport”},“marketCount”:3},{“eventType”:{“id”:“27454571”,“name”:“Esports”},“marketCount”:110},{“eventType”:{“id”:“28361978”,“name”:“Lottery Specials”},“marketCount”:1},{“eventType”:{“id”:“10”,“name”:“Special Bets”},“marketCount”:10},{“eventType”:{“id”:“998917”,“name”:“Volleyball”},“marketCount”:2},{“eventType”:{“id”:“11”,“name”:“Cycling”},“marketCount”:6},{“eventType”:{“id”:“2152880”,“name”:“Gaelic Games”},“marketCount”:2},{“eventType”:{“id”:“3988”

1722-byte body
“”"

How can I access the JSON part of the response?

Isn’t that already explained in the Stackoverflow link?

using JSON
response_text = String(response.body)
JSON.parse(response_text)
2 Likes

I completely missed that. My apologies.