VBA-Excel; JSON-запрос выдает ошибку из-за 0 в ячейках вместо значений - PullRequest
0 голосов
/ 06 ноября 2018

Я написал следующий VBA-макрос

Sub getMatches()

Dim strURL As String
Dim strJSON As String
Dim strCompetition As Integer  
Dim strSeason As Integer 
Dim strMatchDay As Integer
Dim i As Integer

'strURL = "https://api.football-data.org/v2/competitions/2021/matches?matchday=1&season=2019"
strURL = "https://api.football-data.org/v2/competitions/" & strSeason & "/matches?matchday=" & strMatchDay & "&season=" & strSeason
strCompetition = Range("B2").Value  
strSeason = Range("B4").Value
strMatchDay = Range("B6").Value
MsgBox strCompetition
MsgBox strSeason
MsgBox strMatchDay
MsgBox strURL


Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "Get", strURL
MyRequest.setRequestHeader "X-Auth-Token", "personal_code"
MyRequest.Send
Dim Json As Object
Set Json = JsonConverter.ParseJson(MyRequest.ResponseText)
MsgBox MyRequest.ResponseText

Запустив этот скрипт, я получаю следующий вывод:

MsgBox strCompetition

enter image description here

MsgBox strSeason

enter image description here

MsgBox strMatchDay

enter image description here

MsgBox strURL

enter image description here

Почему URL не содержит переменных, которые я объявил ранее? Я хочу, чтобы URL был определен следующим образом: "https://api.football -data.org / v2 / Competitions / 2021 / matchs? Matchday = 1 & season = 2019 "

1 Ответ

0 голосов
/ 06 ноября 2018

Вы устанавливаете значения своих переменных после помещения их в URL. Просто переместите строку создания URL-адреса после того, как вы присвоили все остальные переменные (то же самое с переменной matchday).

strCompetition = Range("B2").Value  
strSeason = Range("B4").Value
strMatchDay = Range("B6").Value

matchday=" & strMatchDay & "&season=" & strSeason
strURL = "https://api.football-data.org/v2/competitions/" & strSeason & "/matches?matchday=" & strMatchDay & "&season=" & strSeason
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...