rcdmk / aspJSON

A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
MIT License
203 stars 89 forks source link

Loop through Properties #20

Closed tbett closed 8 years ago

tbett commented 8 years ago

How do you loop through the available (unknown) properties to retrieve the property name and associated value ...

string = [{"prop1":"value1", "prop2":"value2", "prop3":"value3"}]

Thank you!

rcdmk commented 8 years ago

The JSONobject class has a property named pairs that let's you access directly the property pairs.

<%
dim props, prop
props = json.pairs

for each prop in props
    response.write prop.name & ":" & prop.value & "<br>"
next
%>
tbett commented 8 years ago

So, just to be complete for others. Thanks again!

<%
    dim vJson, json, props, prop
    vJson = "{""prop1"":""value1"", ""prop2"":""value2"", ""prop3"":""value3""}"

    set json = new JSONobject
    json.parse(vJson)

    props = json.pairs
    for each prop in props
        response.write prop.name & " : " & prop.value & "<br>"
    next
%>