I'm getting stuck with the Run-time error '13': Type Mismatch error on displaying data from JSON Array.
Getting stuck at the home3.Cells(vp, 8) = item41("nonVariableListPrice"). I'm trying many different ways and methods by researching google and still unable to solve the problem. May I know if this is a JSON converter problem?
However I'm able to call the other array data from another API without any errors...
Kindly please refer to the below code:
vp = 7
Lastrow2 = Noutput.Cells(Rows.Count, "F").End(xlUp).Row
For id = 2 To Lastrow2 'make a loop call for OpenBasket API
If Cells(id, 6).Value <> "sn?pshot" Then
Dim strUrl62 As String
'For search quote service API-Step1
strUrl62 = Cells(id, 6).Value
'create a method for calling HTTP services
Set hReq62 = CreateObject("MSXML2.XMLHTTP")
With hReq62
.Open "GET", strUrl62, blnAsync, False
'Set the headers for bypassing the API service.
.SetRequestHeader "Authorization", "xxxxxxxxxxxxxxxx" & authKey
.Send
While hReq62.ReadyState <> 4
DoEvents
Wend
'wrap the response in a JSON root tag "data" to count returned objects
strResponse62 = hReq62.ResponseText
End With
Dim Json61 As Object
Set Json61 = JsonConverter.ParseJson(strResponse62)
For Each check41 In Json61
If check41 = "nonVariableListPrice" Then
For Each item41 In Json61
**home3.Cells(vp, 8) = item41("nonVariableListPrice")**
Debug.Print item41
Next item41
Else
home3.Cells(vp, 8).Value = "NO DATA"
End If
Next check41
vp = vp + 1
Screenshots:
Error line of code
JSON Structure
Runtime Error '1004'
"Left" unexpected VS "Right"expected Output in Excel
Example JSON:
{
"associatedItems": [],
"associatedTiedItems": [],
"baseSkuClass": "XZ050",
"baseSkuClassDescription": "CYBERSENSE SUBSCRIPTION",
"baseSkuNumber": "210-AXQX",
"brandId": "1263",
"buildToStock": false,
"catalogId": 18,
"categories": [
{
"name": "CONFIG",
"id": "root",
"parentCategoryId": "-1",
"description": "CONFIG"
},
],
"taxes": [],
"type": "OrderCode",
"weight": 0.0,
"catalogSystemUri": "CFG",
"allowChangeQuantity": true,
"familyName": "CyberSense",
"shipsWith": false,
"nonVariableListPrice": 147876.912,
"nonVariableCost": 0.0,
"catalogCurrency": "USD",
"nonVariableCurrency": "USD",
"nonVariableHedgeRateUsed": 1.0,
"isVariablePriced": true,
"validationResult": {
"isValid": true,
"message": []
},
For each item411 in Json61loop for but tryhome3.Cells(vp, 8) = Json61(check41)just belowIf check41 = "nonVariableListPrice" Then@RaidenFor each item41 in Json61is for looping each of the"nonVariableListPrice"from multiple APIs. I'm calling multiple APIs for retrieving the same data from the Object '"nonVariableListPrice"'. Just tried your wayhome3.Cells(vp, 8) = Json61(check41)just belowIf check41 = "nonVariableListPrice" Thennot getting the data return for the '"nonVariableListPrice"', it went to theElse loopwithNO DATA."For Each loop"is not required and I'm just creating a redundent loop for check the names of the keys.