You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ricardo Souza edited this page Oct 3, 2022
·
2 revisions
A common scenario in JSON data is the use of array structures like
[{"name":"item 1"},{"name":"item 2"}]
or array properties like
{"list":[{"name":"item 1"},{"name":"item 2"}]}
Since we represent arrays with jsonArray objects, we have to use Set to obtain a reference for the array structure when parsing a JSON array string like the first example:
For array properties, we can use the same strategy as above, setting the array reference to another variable and looping its items or access the items property directly in the loop:
<%Set json =new jsonObjectjsonStr ="{""list"":[{""name"":""item 1""},{""name"":""item 2""}]}"' VBS escapes double quotes with double quotesjson.Parse(jsonStr) ' we don't need to set objects to new variables if the string is not an array' setting to another variableSet arr = json("list")Foritemin arr.itemsResponse.Writeitem.("name") &"<br>"Next' OR, accessing the variable directlyForitemin json("list").itemsResponse.Writeitem.("name") &"<br>"Next%>