【发布时间】:2021-12-18 01:56:18
【问题描述】:
我一直在使用JsonConverter 解析JSONfile,然后使用以下代码将dictionary 中的所有“标签”和子“值”提取到我的用户表单combobox 中。
Set JSP = JsonConverter.ParseJson(JSONtxtString)
For Each A In JSP
Debug.Print A
If Not IsObject(JSP(A)) Then
Debug.Print JSP(A)
Else
For Each B In JSP(A)
If Not IsObject(JSP(B)) Then
'Debug.Print B("label")
Me.AttributeComBo.AddItem B("label")
Me.ConditionBox.AddItem B("label")
If B("type") = "selectboxes" Or B("type") = "select" Then
For Each C In B("values")
'Debug.Print C("label")
Me.CBSubValues.AddItem C("label")
Next C
End If
Else
End If
Next B
End If
Next A
但是我无法从“喜欢的颜色”中获取值(“标签”)。来自以下 JSON。
{"components": [
{
"label": "Family Name",
"tableView": true,
"key": "familyName",
"type": "textfield",
"input": true
},
{
"label": "Amount of Money",
"mask": false,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"truncateMultipleSpaces": false,
"key": "amountOfMoney",
"type": "number",
"input": true
},
{
"label": "I hereby confirm",
"tableView": false,
"key": "iHerebyConfirm",
"type": "checkbox",
"input": true,
"defaultValue": false
},
{
"label": "Which Cities do you like",
"optionsLabelPosition": "right",
"tableView": false,
"values": [
{
"label": "New York",
"value": "newNew YorkYork",
"shortcut": ""
},
{
"label": "Munich",
"value": "Munich",
"shortcut": ""
},
{
"label": "Paris",
"value": "Paris",
"shortcut": ""
},
{
"label": "Hongkong",
"value": "Hongkong",
"shortcut": ""
},
{
"label": "Mumbai",
"value": "Mumbai",
"shortcut": ""
}
],
"key": "whichCitiesDoYouLike",
"type": "selectboxes",
"input": true,
"inputType": "checkbox"
},
{
"label": "Favorite color",
"widget": "choicesjs",
"tableView": true,
"data": {
"values": [
{
"label": "black",
"value": "black"
},
{
"label": "white",
"value": "white"
},
{
"label": "blue",
"value": "blue"
},
{
"label": "green",
"value": "green"
}
]
},
"key": "favoriteColor",
"type": "select",
"input": true
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
]
}
我无法从标签(“最喜欢的颜色”)中获取值,即黑色、白色、蓝色、绿色 从任何 JSON 文件中提取所有值的更好解决方案是什么? 如何遍历 JSON 中的每个对象并提取所有值?
【问题讨论】:
标签: arrays json vba dictionary parsing