Parsing JSON in Excel VBA

后端 未结 11 901
长发绾君心
长发绾君心 2020-11-22 09:58

I have the same issue as in Excel VBA: Parsed JSON Object Loop but cannot find any solution. My JSON has nested objects so suggested solution like VBJSON and vba-json do not

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 10:22

    As Json is nothing but strings so it can easily be handled if we can manipulate it the right way, no matter how complex the structure is. I don't think it is necessary to use any external library or converter to do the trick. Here is an example where I've parsed json data using string manipulation.

    Sub FetchData()
        Dim str As Variant, N&, R&
    
        With New XMLHTTP60
            .Open "GET", "https://oresapp.asicanada.net/ores.imis.services/api/member/?address=&callback=angular.callbacks._0&city=&companyName=&personName=", False
            .send
            str = Split(.responseText, ":[{""Id"":")
        End With
    
        N = UBound(str)
    
        For R = 1 To N
            Cells(R, 1) = Split(Split(str(R), "FullName"":""")(1), """")(0)
            Cells(R, 2) = Split(Split(str(R), "Phone"":""")(1), """")(0)
            Cells(R, 3) = Split(Split(str(R), "Email"":""")(1), """")(0)
        Next R
    End Sub
    

提交回复
热议问题