I have been using JsonConverter
to parse JSON
file and then using following code to extract all the "label" and sub "values" from dictionary
into my userform 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
however I could not get the values("label") from "Favorate color". from the following 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
}
]
}
I could not get the values i.e black, white, blue, green from label("Favorite color") WHAT IS THE BETTER SOLUTION TO EXTRACT ALL THE VALUES FROM ANY JSON FILE? how can I loop through each object in JSON and extract all the values?