Problem while parsing a specific JSON in VBA









up vote
0
down vote

favorite












im trying right now parsing mutliple JSONs in VBA in Excel. With Google and SO i managed to parse Multiple JSONs in a Format like this:




"name": "Starker Geschmeidiger Holz-Langbogen des Feuers",
"description": "",
"type": "Weapon",
"level": 44,
"rarity": "Masterwork",
"vendor_value": 120,
"default_skin": 3942,
"game_types": [
"Activity",
"Wvw",
"Dungeon",
"Pve"
],
"flags": [
"SoulBindOnUse"
],
"restrictions": ,
"id": 28445,
"chat_link": "[&AgEdbwAA]",
"icon": "https://render.guildwars2.com/file/C6110F52DF5AFE0F00A56F9E143E9732176DDDE9/65015.png",
"details":
"type": "LongBow",
"damage_type": "Physical",
"min_power": 385,
"max_power": 452,
"defense": 0,
"infusion_slots": ,
"infix_upgrade":
"id": 142,
"attributes": [

"attribute": "Power",
"modifier": 85
,

"attribute": "Precision",
"modifier": 61

]
,
"suffix_item_id": 24547,
"secondary_suffix_item_id": ""




I do it like this:



Private Function Get_Name(id As Integer) As String

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/items/" & id & "?lang=de"

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

Dim oJSON As Object
Set oJSON = JsonConverter.ParseJson(sGetResult)

For Each sItem In oJSON
If sItem = "name" Then
Get_Name = oJSON(sItem)
End If
Next

End Function


That works fine, but i have one JSON i get from the API, that has a different Format and i dont manage to get this to work too.. It hast the following Format:



[

"id": 12134,
"category": 5,
"count": 204
,

"id": 12238,
"category": 5,
"count": 150
,

"id": 12147,
"category": 5,
"count": 146
,

"id": 12142,
"category": 5,
"count": 215
,
....
]


Thats my Try so Far:



Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

MsgBox sGetResult

Dim oJSON As Collection
Set oJSON = JsonConverter.ParseJson(sGetResult)

MsgBox oJSON

For Each sItem In oJSON
'If oJSON(sItem)("id") = id Then
' Get_Anzahl_Im_Lager = oJSON(sItem)("count")
' End If
Get_Anzahl_Im_Lager = sItem
Exit Function
Next

End Function


Problem is,according to the Debugger it parses the Array, but i just get an Empty Object back here, oJSON is empty, while sGetResult hast the JSON Data in it.



Any Solutions?










share|improve this question

















  • 1




    Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
    – drec4s
    Nov 10 at 18:15










  • Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
    – Schesam
    Nov 10 at 18:20










  • I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
    – S Meaden
    Nov 10 at 19:21














up vote
0
down vote

favorite












im trying right now parsing mutliple JSONs in VBA in Excel. With Google and SO i managed to parse Multiple JSONs in a Format like this:




"name": "Starker Geschmeidiger Holz-Langbogen des Feuers",
"description": "",
"type": "Weapon",
"level": 44,
"rarity": "Masterwork",
"vendor_value": 120,
"default_skin": 3942,
"game_types": [
"Activity",
"Wvw",
"Dungeon",
"Pve"
],
"flags": [
"SoulBindOnUse"
],
"restrictions": ,
"id": 28445,
"chat_link": "[&AgEdbwAA]",
"icon": "https://render.guildwars2.com/file/C6110F52DF5AFE0F00A56F9E143E9732176DDDE9/65015.png",
"details":
"type": "LongBow",
"damage_type": "Physical",
"min_power": 385,
"max_power": 452,
"defense": 0,
"infusion_slots": ,
"infix_upgrade":
"id": 142,
"attributes": [

"attribute": "Power",
"modifier": 85
,

"attribute": "Precision",
"modifier": 61

]
,
"suffix_item_id": 24547,
"secondary_suffix_item_id": ""




I do it like this:



Private Function Get_Name(id As Integer) As String

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/items/" & id & "?lang=de"

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

Dim oJSON As Object
Set oJSON = JsonConverter.ParseJson(sGetResult)

For Each sItem In oJSON
If sItem = "name" Then
Get_Name = oJSON(sItem)
End If
Next

End Function


That works fine, but i have one JSON i get from the API, that has a different Format and i dont manage to get this to work too.. It hast the following Format:



[

"id": 12134,
"category": 5,
"count": 204
,

"id": 12238,
"category": 5,
"count": 150
,

"id": 12147,
"category": 5,
"count": 146
,

"id": 12142,
"category": 5,
"count": 215
,
....
]


Thats my Try so Far:



Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

MsgBox sGetResult

Dim oJSON As Collection
Set oJSON = JsonConverter.ParseJson(sGetResult)

MsgBox oJSON

For Each sItem In oJSON
'If oJSON(sItem)("id") = id Then
' Get_Anzahl_Im_Lager = oJSON(sItem)("count")
' End If
Get_Anzahl_Im_Lager = sItem
Exit Function
Next

End Function


Problem is,according to the Debugger it parses the Array, but i just get an Empty Object back here, oJSON is empty, while sGetResult hast the JSON Data in it.



Any Solutions?










share|improve this question

















  • 1




    Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
    – drec4s
    Nov 10 at 18:15










  • Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
    – Schesam
    Nov 10 at 18:20










  • I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
    – S Meaden
    Nov 10 at 19:21












up vote
0
down vote

favorite









up vote
0
down vote

favorite











im trying right now parsing mutliple JSONs in VBA in Excel. With Google and SO i managed to parse Multiple JSONs in a Format like this:




"name": "Starker Geschmeidiger Holz-Langbogen des Feuers",
"description": "",
"type": "Weapon",
"level": 44,
"rarity": "Masterwork",
"vendor_value": 120,
"default_skin": 3942,
"game_types": [
"Activity",
"Wvw",
"Dungeon",
"Pve"
],
"flags": [
"SoulBindOnUse"
],
"restrictions": ,
"id": 28445,
"chat_link": "[&AgEdbwAA]",
"icon": "https://render.guildwars2.com/file/C6110F52DF5AFE0F00A56F9E143E9732176DDDE9/65015.png",
"details":
"type": "LongBow",
"damage_type": "Physical",
"min_power": 385,
"max_power": 452,
"defense": 0,
"infusion_slots": ,
"infix_upgrade":
"id": 142,
"attributes": [

"attribute": "Power",
"modifier": 85
,

"attribute": "Precision",
"modifier": 61

]
,
"suffix_item_id": 24547,
"secondary_suffix_item_id": ""




I do it like this:



Private Function Get_Name(id As Integer) As String

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/items/" & id & "?lang=de"

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

Dim oJSON As Object
Set oJSON = JsonConverter.ParseJson(sGetResult)

For Each sItem In oJSON
If sItem = "name" Then
Get_Name = oJSON(sItem)
End If
Next

End Function


That works fine, but i have one JSON i get from the API, that has a different Format and i dont manage to get this to work too.. It hast the following Format:



[

"id": 12134,
"category": 5,
"count": 204
,

"id": 12238,
"category": 5,
"count": 150
,

"id": 12147,
"category": 5,
"count": 146
,

"id": 12142,
"category": 5,
"count": 215
,
....
]


Thats my Try so Far:



Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

MsgBox sGetResult

Dim oJSON As Collection
Set oJSON = JsonConverter.ParseJson(sGetResult)

MsgBox oJSON

For Each sItem In oJSON
'If oJSON(sItem)("id") = id Then
' Get_Anzahl_Im_Lager = oJSON(sItem)("count")
' End If
Get_Anzahl_Im_Lager = sItem
Exit Function
Next

End Function


Problem is,according to the Debugger it parses the Array, but i just get an Empty Object back here, oJSON is empty, while sGetResult hast the JSON Data in it.



Any Solutions?










share|improve this question













im trying right now parsing mutliple JSONs in VBA in Excel. With Google and SO i managed to parse Multiple JSONs in a Format like this:




"name": "Starker Geschmeidiger Holz-Langbogen des Feuers",
"description": "",
"type": "Weapon",
"level": 44,
"rarity": "Masterwork",
"vendor_value": 120,
"default_skin": 3942,
"game_types": [
"Activity",
"Wvw",
"Dungeon",
"Pve"
],
"flags": [
"SoulBindOnUse"
],
"restrictions": ,
"id": 28445,
"chat_link": "[&AgEdbwAA]",
"icon": "https://render.guildwars2.com/file/C6110F52DF5AFE0F00A56F9E143E9732176DDDE9/65015.png",
"details":
"type": "LongBow",
"damage_type": "Physical",
"min_power": 385,
"max_power": 452,
"defense": 0,
"infusion_slots": ,
"infix_upgrade":
"id": 142,
"attributes": [

"attribute": "Power",
"modifier": 85
,

"attribute": "Precision",
"modifier": 61

]
,
"suffix_item_id": 24547,
"secondary_suffix_item_id": ""




I do it like this:



Private Function Get_Name(id As Integer) As String

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/items/" & id & "?lang=de"

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

Dim oJSON As Object
Set oJSON = JsonConverter.ParseJson(sGetResult)

For Each sItem In oJSON
If sItem = "name" Then
Get_Name = oJSON(sItem)
End If
Next

End Function


That works fine, but i have one JSON i get from the API, that has a different Format and i dont manage to get this to work too.. It hast the following Format:



[

"id": 12134,
"category": 5,
"count": 204
,

"id": 12238,
"category": 5,
"count": 150
,

"id": 12147,
"category": 5,
"count": 146
,

"id": 12142,
"category": 5,
"count": 215
,
....
]


Thats my Try so Far:



Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

MsgBox sGetResult

Dim oJSON As Collection
Set oJSON = JsonConverter.ParseJson(sGetResult)

MsgBox oJSON

For Each sItem In oJSON
'If oJSON(sItem)("id") = id Then
' Get_Anzahl_Im_Lager = oJSON(sItem)("count")
' End If
Get_Anzahl_Im_Lager = sItem
Exit Function
Next

End Function


Problem is,according to the Debugger it parses the Array, but i just get an Empty Object back here, oJSON is empty, while sGetResult hast the JSON Data in it.



Any Solutions?







arrays json vba parsing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 18:04









Schesam

419




419







  • 1




    Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
    – drec4s
    Nov 10 at 18:15










  • Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
    – Schesam
    Nov 10 at 18:20










  • I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
    – S Meaden
    Nov 10 at 19:21












  • 1




    Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
    – drec4s
    Nov 10 at 18:15










  • Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
    – Schesam
    Nov 10 at 18:20










  • I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
    – S Meaden
    Nov 10 at 19:21







1




1




Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
– drec4s
Nov 10 at 18:15




Any reason why you made Dim oJSON As Collection instead of Dim oJSON as Object?
– drec4s
Nov 10 at 18:15












Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
– Schesam
Nov 10 at 18:20




Yes, i had is as an Object, but since it doesnt work, i tried to change it do Collection, since internally, for Arrays a Collection is made, but if i write "Object" or "Collection", both stay empty
– Schesam
Nov 10 at 18:20












I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
– S Meaden
Nov 10 at 19:21




I prefer to use Script Control and Douglas Crockford's own JSON parsing library, exceldevelopmentplatform.blogspot.com/2018/01/…
– S Meaden
Nov 10 at 19:21












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










Made it.. Sometimes i should just start thinking from a new Point on :D



Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")

If Not IsEmpty(Tabelle2.Cells(1, 7)) Then
sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)
Else
Exit Function
End If

sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.send
sGetResult = httpObject.responseText

Dim oJSON As Object
Set oJSON = JsonConverter.ParseJson(sGetResult)

Dim sItem, cnt&
For Each sItem In oJSON
cnt = cnt + 1
If oJSON(cnt)("id") = id Then
Get_Anzahl_Im_Lager = oJSON(cnt)("count")
Exit Function
End If
Next

End Function





share|improve this answer



























    up vote
    0
    down vote













    The JSON objects are of two different types. One is dictionary and one is a collection. Use TypeName to determine which you are getting from the responseText and handle as required e.g.



    Dim item As Long, oJSON As Object
    Set oJSON = JsonConverter.ParseJson(sGetResult)

    Select Case TypeName(oJSON)

    Case "Collection"

    For Each item In json
    Debug.Print item("count")
    Next

    Case "Dictionary"

    Debug.Print json("name")

    End Select





    share|improve this answer






















    • Did you try this?
      – QHarr
      Nov 11 at 12:36










    • No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
      – Schesam
      Nov 12 at 12:08










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241905%2fproblem-while-parsing-a-specific-json-in-vba%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Made it.. Sometimes i should just start thinking from a new Point on :D



    Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

    Dim httpObject As Object
    Set httpObject = CreateObject("MSXML2.XMLHTTP")

    If Not IsEmpty(Tabelle2.Cells(1, 7)) Then
    sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)
    Else
    Exit Function
    End If

    sRequest = sURL
    httpObject.Open "GET", sRequest, False
    httpObject.send
    sGetResult = httpObject.responseText

    Dim oJSON As Object
    Set oJSON = JsonConverter.ParseJson(sGetResult)

    Dim sItem, cnt&
    For Each sItem In oJSON
    cnt = cnt + 1
    If oJSON(cnt)("id") = id Then
    Get_Anzahl_Im_Lager = oJSON(cnt)("count")
    Exit Function
    End If
    Next

    End Function





    share|improve this answer
























      up vote
      0
      down vote



      accepted










      Made it.. Sometimes i should just start thinking from a new Point on :D



      Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

      Dim httpObject As Object
      Set httpObject = CreateObject("MSXML2.XMLHTTP")

      If Not IsEmpty(Tabelle2.Cells(1, 7)) Then
      sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)
      Else
      Exit Function
      End If

      sRequest = sURL
      httpObject.Open "GET", sRequest, False
      httpObject.send
      sGetResult = httpObject.responseText

      Dim oJSON As Object
      Set oJSON = JsonConverter.ParseJson(sGetResult)

      Dim sItem, cnt&
      For Each sItem In oJSON
      cnt = cnt + 1
      If oJSON(cnt)("id") = id Then
      Get_Anzahl_Im_Lager = oJSON(cnt)("count")
      Exit Function
      End If
      Next

      End Function





      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Made it.. Sometimes i should just start thinking from a new Point on :D



        Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

        Dim httpObject As Object
        Set httpObject = CreateObject("MSXML2.XMLHTTP")

        If Not IsEmpty(Tabelle2.Cells(1, 7)) Then
        sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)
        Else
        Exit Function
        End If

        sRequest = sURL
        httpObject.Open "GET", sRequest, False
        httpObject.send
        sGetResult = httpObject.responseText

        Dim oJSON As Object
        Set oJSON = JsonConverter.ParseJson(sGetResult)

        Dim sItem, cnt&
        For Each sItem In oJSON
        cnt = cnt + 1
        If oJSON(cnt)("id") = id Then
        Get_Anzahl_Im_Lager = oJSON(cnt)("count")
        Exit Function
        End If
        Next

        End Function





        share|improve this answer












        Made it.. Sometimes i should just start thinking from a new Point on :D



        Private Function Get_Anzahl_Im_Lager(id As Integer) As Integer

        Dim httpObject As Object
        Set httpObject = CreateObject("MSXML2.XMLHTTP")

        If Not IsEmpty(Tabelle2.Cells(1, 7)) Then
        sURL = "https://api.guildwars2.com/v2/account/materials?access_token=" & Tabelle2.Cells(1, 7)
        Else
        Exit Function
        End If

        sRequest = sURL
        httpObject.Open "GET", sRequest, False
        httpObject.send
        sGetResult = httpObject.responseText

        Dim oJSON As Object
        Set oJSON = JsonConverter.ParseJson(sGetResult)

        Dim sItem, cnt&
        For Each sItem In oJSON
        cnt = cnt + 1
        If oJSON(cnt)("id") = id Then
        Get_Anzahl_Im_Lager = oJSON(cnt)("count")
        Exit Function
        End If
        Next

        End Function






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 19:31









        Schesam

        419




        419






















            up vote
            0
            down vote













            The JSON objects are of two different types. One is dictionary and one is a collection. Use TypeName to determine which you are getting from the responseText and handle as required e.g.



            Dim item As Long, oJSON As Object
            Set oJSON = JsonConverter.ParseJson(sGetResult)

            Select Case TypeName(oJSON)

            Case "Collection"

            For Each item In json
            Debug.Print item("count")
            Next

            Case "Dictionary"

            Debug.Print json("name")

            End Select





            share|improve this answer






















            • Did you try this?
              – QHarr
              Nov 11 at 12:36










            • No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
              – Schesam
              Nov 12 at 12:08














            up vote
            0
            down vote













            The JSON objects are of two different types. One is dictionary and one is a collection. Use TypeName to determine which you are getting from the responseText and handle as required e.g.



            Dim item As Long, oJSON As Object
            Set oJSON = JsonConverter.ParseJson(sGetResult)

            Select Case TypeName(oJSON)

            Case "Collection"

            For Each item In json
            Debug.Print item("count")
            Next

            Case "Dictionary"

            Debug.Print json("name")

            End Select





            share|improve this answer






















            • Did you try this?
              – QHarr
              Nov 11 at 12:36










            • No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
              – Schesam
              Nov 12 at 12:08












            up vote
            0
            down vote










            up vote
            0
            down vote









            The JSON objects are of two different types. One is dictionary and one is a collection. Use TypeName to determine which you are getting from the responseText and handle as required e.g.



            Dim item As Long, oJSON As Object
            Set oJSON = JsonConverter.ParseJson(sGetResult)

            Select Case TypeName(oJSON)

            Case "Collection"

            For Each item In json
            Debug.Print item("count")
            Next

            Case "Dictionary"

            Debug.Print json("name")

            End Select





            share|improve this answer














            The JSON objects are of two different types. One is dictionary and one is a collection. Use TypeName to determine which you are getting from the responseText and handle as required e.g.



            Dim item As Long, oJSON As Object
            Set oJSON = JsonConverter.ParseJson(sGetResult)

            Select Case TypeName(oJSON)

            Case "Collection"

            For Each item In json
            Debug.Print item("count")
            Next

            Case "Dictionary"

            Debug.Print json("name")

            End Select






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 at 12:37

























            answered Nov 10 at 19:27









            QHarr

            25.7k81839




            25.7k81839











            • Did you try this?
              – QHarr
              Nov 11 at 12:36










            • No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
              – Schesam
              Nov 12 at 12:08
















            • Did you try this?
              – QHarr
              Nov 11 at 12:36










            • No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
              – Schesam
              Nov 12 at 12:08















            Did you try this?
            – QHarr
            Nov 11 at 12:36




            Did you try this?
            – QHarr
            Nov 11 at 12:36












            No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
            – Schesam
            Nov 12 at 12:08




            No, but that Solution will i keep in Mind. In my Case, each JSON i get from the API with same Parameters has same Format, so i dont need to Separate, which Format i have to Parse. But I think this will hapen in the Future, so i will keep it
            – Schesam
            Nov 12 at 12:08

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241905%2fproblem-while-parsing-a-specific-json-in-vba%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto