chia hoo Ray Hee
New Member
Members
Forum Posts: 2
Member Since:
June 16, 2020
June 16, 2020
Offline
Hello everyone,
I try to run the VBA code as below but it is compile error "Run time error "424":Object require" on Set GetJSON = JSONConverter.ParseJson(.responseText).
Appreciate someone can guide me to find out what is the error mean for?
Sub Test() Const sURL As String = "https://eservices.mas.gov.sg/api/action/datastore/search.json?resource_id=95932927-c8bc-4e7a-b484-68a66a24edfe&fields=end_of_day,jpy_sgd_100&limit=10&sort=end_of_day%20desc" Dim a, ws As Worksheet, json As Object, colData As Collection, m As Long Set ws = ThisWorkbook.Worksheets("Sheet1") Set json = GetJSON(sURL) Set colData = json("result")("records") a = CollectionToArray(colData) With ws .Cells.ClearContents .Range("A1").Resize(1, 2).Value = Array("End Of Day", "Amount") .Range("A2").Resize(UBound(a, 1), UBound(a, 2)).Value = a End With Set json = Nothing: Set colData = Nothing End Sub Function GetJSON(ByVal sURL As String) As Object Dim http As MSXML2.XMLHTTP60 Set http = New MSXML2.XMLHTTP60 With http .Open "Get", sURL, False .setRequestHeader "User-Agent", "Mozilla/5.0" .send Set GetJSON = JSONConverter.ParseJson(.responseText) End With End Function Function CollectionToArray(c As Collection) As Variant() Dim a(), i As Long, j As Long ReDim a(1 To c.Count, 1 To 2) For i = 1 To c.Count a(i, 1) = c.Item(i)("end_of_day") a(i, 2) = c.Item(i)("jpy_sgd_100") Next i CollectionToArray = a End Function
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
1 Guest(s)
Top Posters:
Catalin Bombea: 1944
SunnyKow: 1432
Anders Sehlstedt: 956
Purfleet: 415
Hans Hallebeek: 377
Frans Visser: 351
David_Ng: 318
lea cohen: 248
Jessica Stewart: 219
A.Maurizio: 216
Newest Members:
Techia Braveboy
Charles Buchanan
Tiago Braga
Rehan Baig
Fred HORVATH
Silke Schmidt
Stuart Barr
Amelia Nolte
David Wier
T P Collins
Forum Stats:
Groups: 3
Forums: 25
Topics: 7154
Posts: 31382
Member Stats:
Guest Posters: 50
Members: 34655
Moderators: 2
Admins: 3
Administrators: Mynda Treacy, Philip Treacy, Jessica
Moderators: Velouria, Riny van Eekelen
© Simple:Press —