在Excel VBA中的JSON响应内解析数组对象

问题描述 投票:0回答:1

我的JSON响应:

{"type":"FeatureCollection","totalFeatures":1,"features":[{"type":"Feature","id":"pand3d.6317078","geometry":{"type":"Polygon","coordinates":[[[125290.418,479247.512,0],[125289.696,479248.817,0],[125287.842,479247.791,0],[125264.136,479234.672,0],[125262.123,479233.558,0],[125262.675,479232.56,0],[125281.04,479199.376,0],[125281.226,479199.039,0],[125283.611,479200.359,0],[125286.739,479202.09,0],[125287.237,479202.366,0],[125289.944,479203.864,0],[125290.547,479204.198,0],[125299.388,479209.09,0],[125299.965,479209.409,0],[125302.747,479210.949,0],[125303.148,479211.171,0],[125306.787,479213.185,0],[125308.799,479214.298,0],[125308.765,479214.36,0],[125290.418,479247.512,0]]]},"geometry_name":"geovlak","properties":{"gid":6317078,"identificatie":"0363100012148538","aanduidingrecordinactief":false,"aanduidingrecordcorrectie":0,"officieel":false,"inonderzoek":false,"documentnummer":"GV00000406","documentdatum":"2010-09-09Z","bouwjaar":"2005-01-01Z","begindatumtijdvakgeldigheid":"2010-09-08T22:00:00Z","einddatumtijdvakgeldigheid":null,"gemeentecode":"0363","ground-0.00":-3.64,"ground-0.10":-0.9,"ground-0.20":-0.89,"ground-0.30":-0.88,"ground-0.40":-0.88,"ground-0.50":-0.87,"roof-0.25":27.52,"rmse-0.25":1.09,"roof-0.50":27.57,"rmse-0.50":1.09,"roof-0.75":29.91,"rmse-0.75":1.08,"roof-0.90":30.24,"rmse-0.90":1.08,"roof-0.95":30.35,"rmse-0.95":1.08,"roof-0.99":30.36,"rmse-0.99":1.08,"roof_flat":false,"nr_ground_pts":3515,"nr_roof_pts":6432,"ahn_file_date":"2014-02-01T23:00:00Z","ahn_version":3,"height_valid":true,"tile_id":"25gz2","bbox":[125262.123,479199.039,125308.799,479248.817]}}],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::28992"}},"bbox":[125262.123,479199.039,125308.799,479248.817]}

我想从数组["roof-0.99":30.36]中的{properties}对象解析[features],但收到“无效参数”的错误]

这是我的尝试

Sub BAG3D()

    Dim ws As Worksheet: Set ws = Blad1

    'Variabeles for function
    Dim BAG3D As Object

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

    objHTTP.Open "GET", "http://3dbag.bk.tudelft.nl/data/wfs?SERVICE=WFS&REQUEST=GetFeature&TYPENAMES=BAG3D:pand3d&CQL_FILTER=identificatie=%270363100012148538%27&outputFormat=json", False
'    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
'    objHTTP.setRequestHeader "Accept", "application/hal+json"
'    objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
'    objHTTP.setRequestHeader "X-Api-Key", KEY

    objHTTP.send

    Set BAG3D = ParseJson(objHTTP.responseText)
    Debug.Print objHTTP.responseText

    For Each Item In BAG3D("features")(0)("0")("properties")
        'Look for "roof-0.99" and get value
        ws.Range("Y3").Value = BAG3D("roof-0.99") 'probably not right
    Next
End Sub

我应该在解析器中进行哪些修改,以将Roof-0.99正确解析到电子表格中?

json excel excel-vba parsing jsonconvert
1个回答
0
投票
Sub BAG3D()

    Dim ws As Worksheet: Set ws = Blad1

    'Variabeles for function
    Dim BAG3D As Object

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

    objHTTP.Open "GET", "http://3dbag.bk.tudelft.nl/data/wfs?SERVICE=WFS&REQUEST=GetFeature&TYPENAMES=BAG3D:pand3d&CQL_FILTER=identificatie=%270363100012148538%27&outputFormat=json", False
'    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
'    objHTTP.setRequestHeader "Accept", "application/hal+json"
'    objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
'    objHTTP.setRequestHeader "X-Api-Key", KEY

    objHTTP.send

    Set BAG3D = ParseJson(objHTTP.responseText)
    Debug.Print objHTTP.responseText

    ws.Range("Y3").Value = BAG3D("features")(1)("properties")("roof-0.99")
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.