我尝试使用vba将json数据提取到excel表中。我已经安装了VBA-JSON并打开了Microsoft脚本运行时。
json请求提供:
{“ STATUS”:“成功”,“结果”:{“ aid”:“ 17903”,“ ean”:4003483179030,“ title”:“曼萨尼塔(Manzanita),sandgestrahlt,verzweigt,90-100厘米”,“ shortdesc”:“ EchteÄstedirekt aus der der Natur,大约90-100 Zentimeter lang。 ,“ longdesc”:“ Ein besonderer Blickfang sind Dekorationen aus echten,NatürlichenMaterialien wie MANZANITA Zweigen。 ,“ length”:“ 0”,“ width”:“ 0”,“ height”:“ 90”,“ weight”:“ 1”,“ pic01”:“ 17903_manzanitasandblastedbranchy.jpg”,“ pic02”:“ 17903_manzanitasandblastedbranchy〜01.jpg”,“ pic03”:“ 17903_manzanitasandblastedbranchy〜02.jpg”,“ pic04”:“”,“ pic05”:“”,“ pic06”:“”,“ pic07”:“”,“ pic08”:“”,“ pic09”:“”,“ pic10”:“”,“ pic11”:“”,“ pic12”:“”,“属性”:[{“ id”:“ oxattribute1013”,“ title”:“ Aktueller Katalog”,“值”:“ 1”},{“ id”:“ oxattribute1021”,“ title”:“ Aktueller Katalog-Seitenzahl”,“值”:“ 238-1”},{“ id”:“ oxattribute1007”,“ title”:“ Paket-Versand”,“值”:“ 1”},{“ id”:“ oxattribute1020”,“ title”:“ Serie”,“ value”:“ MANZANITA”},{“ id”:“ oxattribute1019”,“ title”:“ Funktionsname”,“ value”:“ Ast”},{“ id”:“ oxattribute1018”,“ title”:“ Farbbezeichnung”,“ value”:“ sandgestrahlt”},{“ id”:“ oxattribute1005”,“ title”:“ Speditionsversand”,“值”:“ 1”}]}}
我在excel单元(1,1)中编写了它,并使用jsonconverter对其进行了解析。
带有代码
Sub Jsonauslesenbenny()
Dim jsonText As String
Dim jsonObject As Object
Dim i As Long
Dim ws As Worksheet
Set ws = Worksheets("Tabelle1")
jsonText = ws.Cells(1, 1)
Set jsonObject = JsonConverter.ParseJson(jsonText)
i = 3
For Each item In jsonObject("RESULT")
Sheets(1).Cells(i, 1).Value = item("aid")
Sheets(1).Cells(i, 2).Value = item("ean")
Sheets(1).Cells(i, 3).Value = item("title")
i = i + 1
Next
End Sub
以这种方式,可以在excel单元格中写入项目“ aid”至“ pic12”。
我不知道在excel表单元格中的“属性”之后写项目。
如何将json数据中的“ id”,“ title”和“ value”写入excel表?
尝试此代码
Sub Jsonauslesenbenny()
Dim ws As Worksheet, jsonObject As Object, jsonText As String, i As Long
Set ws = Worksheets("Tabelle1")
jsonText = ws.Cells(1, 1)
Set jsonObject = JSONConverter.ParseJson(jsonText)
i = 3
With Sheets(1)
.Cells(i, 1).Value = jsonObject("RESULT")("aid")
.Cells(i, 2).Value = jsonObject("RESULT")("ean")
.Cells(i, 3).Value = jsonObject("RESULT")("title")
End With
End Sub
要获得礼服
Sub GetAttributes()
Dim itm, ws As Worksheet, jsonObject As Object, jsonText As String, i As Long
Set ws = Worksheets("Tabelle1")
jsonText = ws.Cells(1, 1)
Set jsonObject = JSONConverter.ParseJson(jsonText)
i = 3
For Each itm In jsonObject("RESULT")("attributes")
With Sheets(1)
.Cells(i, 1).Value = itm("id")
.Cells(i, 2).Value = itm("title")
.Cells(i, 3).Value = itm("value")
End With
i = i + 1
Next itm
End Sub