"EnTerr" wrote:
I notice that documentation has been updated to say"ifAssociativeArray.Append(aa as Object)" wrote:So it is behavior (B), the new AA overrides old AA content in case of overlapping keys. As any experienced developer would expect but now is in the RTFM and can be relied upon.
... If any key in aa are already associated with a value in this AssociativeArray, the current value is discarded and is replaced with the value in aa.
My gratitude goes to the forum's patron saint, RokuMarkn - thank you!
"TheEndless" wrote:
It's probably worth noting that case matters in this instance as well. So, if you have a key named "Test" and you append an AA with a key named "test", you'll end up with two separate keys.
"renojim" wrote:
That's interesting. Could that be considered a bug?
BrightScript Debugger> d = {}
BrightScript Debugger> d["Test"] = "Test"
BrightScript Debugger> ?d
Test: Test
BrightScript Debugger> d2 = {}
BrightScript Debugger> d2["test"] = "test"
BrightScript Debugger> ? d2
test: test
BrightScript Debugger> d.append(d2)
BrightScript Debugger> ?d
test: test
"TheEndless" wrote:
It's probably worth noting that case matters in this instance as well. So, if you have a key named "Test" and you append an AA with a key named "test", you'll end up with two separate keys.
BrightScript Debugger> test1 = ParseJSON("{" + Chr(34) + "Test" + Chr(34) + ": true}")
BrightScript Debugger> test2 = ParseJSON("{" + Chr(34) + "test" + Chr(34) + ": false}")
BrightScript Debugger> ?test1
Test: true
BrightScript Debugger> ?test2
test: false
BrightScript Debugger> test2.Append(test1)
BrightScript Debugger> ?test2
Test: true
test: false
"squirreltown" wrote:
Brightscript is case-insensitive except for the registry, right? Anything else?
The dot operator is always case insensitive. By convention, a statement like:
aa.NewKey = 55
Will actually create the Associative Array entry in all lower case ("newkey"). The array operator or the ifAssociativeArray.AddReplace method can be used to create mixed case keys.
"TheEndless" wrote:
Sorry, it seems case sensitivity is on when parsing a JSON string, so this is only true if you call the SetModeCaseSensitive() explicitly, or if your AA comes from a parsed JSON string.
BrightScript Debugger> test1 = ParseJSON("{" + Chr(34) + "Test" + Chr(34) + ": true}")It was a guess and i tested it - turns out .append() honors the case-sensitivity mode flag of the host AA, so just pouring from a case-sensitive into an insensitive AA "fixes" our issue. IMO things are in order here.
BrightScript Debugger> test2 = {}
BrightScript Debugger> test2.append( ParseJSON("{" + Chr(34) + "test" + Chr(34) + ": false}") )
BrightScript Debugger> ? test2
test: false
BrightScript Debugger> test2.append(test1)
BrightScript Debugger> ? test2
Test: true