Closed Luk4 closed 7 years ago
Hi.
You should be able to change the child JSON object directly as you do with the parent object.
Please post some code if this does not answer the question.
Thank you.
Thanks for your help!
Here is the code I am using:
set JSON = New JSONobject
set JSON2 = New JSONobject
set rs = OpenRecordset("SELECT 'Joe' AS Name, 23 AS Age, 1 AS EyeColor")
JSON.LoadRecordset rs
set rs2 = OpenRecordset("SELECT 1 AS Id, 'Blue' AS Color")
JSON2.defaultPropertyName = "Type"
JSON2.LoadRecordset rs2
JSON.Add "options", JSON2
response.write JSON.Write()
And the output I get is:
{
"data":[
{ "Name":"Joe",
"Age":23,
"EyeColor":1 }
],
"options":{
"data":[
{ "Id":1,
"Color":"Blue" }
] }}
And instead I was hoping to get Type as the defaultPropertyName for the "options" property...
How could I do that?
Thank you!
I found a workaround, which is probably at the expense of performance.
Replacing
JSON.Add "options", JSON2
with
JSON.Add "options", JSON2.Parse(JSON2.Serialize())
does the trick, because obviously the JSONobject is treated like a brand new "hardcoded" object and not as the result of a LoadRecorset. It is a bit of a waste of CPU cycles, though.
Is there a better way to stop inheritance of defaultPropertyName?
Thank you!
Hi.
I need to take a look at the code and maybe do some adjustments.
I should have some time this weekend.
Anyway, you will receive a notification anytime in case I fix this.
Hi Rcdmk and friends -- and thanks to Rcdmk for this outstanding piece of code!!
I have a question about the defaultPropertyName, In my code, I am nesting into a JSONobject two recordsets, loaded with LoadRecordset. In the second recordset, which goes into a property of the first, I would need a different defaultPropertyName (ie. parent defaultPropertyName is "data", child defaultPropertyName is "type"). Unfortunately, it seems that the second recordset will inherit the defaultPropertyName property name of its parent.
Is there a reason for this, and how can achieve the desired result?
Thank you very much for your time and attention!