Closed manattweb closed 6 years ago
Hi! Can you be a bit more specific, please?
Maybe providing some example code.
If you are trying to get the value of an object's property, you can easily use parentheses syntax:
Set jsonObj = new jsonObject
jsonObj.Parse(myaJsonString)
Response.Write jsonObj("my_property")
Hope this helps.
I figured it out - sorry for the bother.
Hi! No worries. It is common to have people asking this. It is my fault actually, for not having this better documented.
Bests.
One more question: To get a value of a nested group of values, would you treat those as an array? Example: JSON("source(0)") to get the first value in that subset or would you do something else like setting an array variable of the node and then pulling out the value you need?
If you have a property that is an array, it will be parsed to a jsonArray object and you can access its items through the Items property:
Response.Write JSON("source").items(0)
' or
Set arr = JSON("source")
Response.Write arr.items(0)
Is your tool expecting "[" as part of the JSON file? Mine doesn't have those and I'm getting the following error: Object doesn't support this property or method: 'JSON(...).items'
Here's the sanitized partial JSON string I'm working with:
testData = "{""shipping"": null, ""source"": { ""id"": ""123456789"", ""object"": ""card"", ""address_city"": ""little rock"", ""address_country"": null, ""address_line1"": ""123 Main St"", ""address_line1_check"": ""pass"", ""address_line2"": null, ""address_state"": ""ar"", ""address_zip"": ""72223"", ""address_zip_check"": ""pass"", ""brand"": ""Visa"", ""country"": ""GB"", ""customer"": null, ""cvc_check"": ""pass"", ""dynamic_last4"": null, ""exp_month"": 1, ""exp_year"": 2019, ""fingerprint"": ""lux5iu1qzm8BLoaj"", ""funding"": ""credit"", ""last4"": ""4242"", ""metadata"": {}, ""name"": null, ""tokenization_method"": null }, ""source_transfer"": null, ""statement_descriptor"": null, ""status"": ""succeeded"", ""transfer_group"": null }""
And this is the code I'm using to try to get that information inside the "source" node:
set JSON = New JSONobject JSON.Parse(testData) Set addressArr = JSON.Value("source") txn_id = addressArr.items(0)
Thoughts?
Oh. Now I see. You have a nested object, not an array. You can access the property value the same way you access the parent one:
Set source = JSON("source")
Response.Write source("id")
' or
Response.Write JSON("source")("id")
thanks for your patience and assistance. The solution is now complete and working great. I appreciate your hard work on this.
You are welcome. Thank you.
I'm getting a JSON object back from Stripe and need to pull out a specific value. How do I do that?