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
204 stars 89 forks source link

Selecting child elements #14

Closed tbett closed 8 years ago

tbett commented 8 years ago

Great project. What is the method for selecting a child element? For example - dimensions > length. JSON("dimensions")("length")?

Also, select by index value for json object array - JSON(0)("dimensions")("length")?

[ { "id": 2, "name": "An ice sculpture", "price": 12.50, "tags": ["cold", "ice"], "dimensions": { "length": 7.0, "width": 12.0, "height": 9.5 } } ]

rcdmk commented 8 years ago

Thank you.

You are almost there.

All you need to do is to assign the returning value of the parse() method to an object and it will give you a reference to a JSONarray object.

set jsonArr = JSON.parse(yourJSONarrayString)

response.write jsonArr(0)("dimensions")("length") ' direct and easy access, valid for single operations

If you have to access many fields, a better (faster) way should be:

set obj = jsonArr(0)
set dimensions = obj("dimensions")

response.write dimensions("length")
tbett commented 8 years ago

Thank you! This is exactly the package that is needed to extend ASP Classic a couple more years!!! Again, thank you for taking the time to put this together and answering my questions so quickly.

rcdmk commented 8 years ago

You are welcome. I'm pleased to have made something useful.