Dear Kevin,
I fail to understand your question and, seeing that it is completely unanswered for days, I suspect that others face the same problem.
First of all: "COS" is "Caché Object Script", right? Just to make sure we are on the same page here.
There is nothing inherent in ObjectScript concerning username/password I know of. These are just scripts running on the Caché sever. So, creating the notorious HelloWorld.mac:
write "Hello World" quit
it can be executed from the terminal command prompt:
mycache:USER>do ^HelloWorld
Hello World
mycache:USER>
Could you maybe provide some context and - preferably - a (sanitized) example?
Regards
Matthias
I would recommend a different structure to the JSON since an array node can hold both, a value and subnodes. This should be reflected in the JSON. So, for an array:
a(1)="A"
a(1,1)="AA"
a(1,2)="AB"
a(1,2,1)="ABA"
a(1,3,1)="ACA"
a(2,1)="BA"
a(3)="C"
a(3,1)="CA"
I suggest to generate an JSON in the form:
{"1":["A",{"1":["AA"],"2":["AB",{"1":["ABA"]}],"3":[{"1":["ACA"]}]}],"2":[{"1":["BA"]}],"3":["C",{"1":["CA"]}]}
This may not be the most convenient for the receiving end to read, but it can hold the full information from the array. This can easily be created using a recursive procedure:
/// Converts an arbitrary array into an JSON-Structure returned /// as %DynamicObject. Subnodes are read recursively, so there /// might be a limit tothe number of levels that can be read. /// /// Usage example: /// >set a(1)="A" /// >set a(1,1)="AA" /// >set a(1,2)="AB" /// >set a(1,2,1)="ABA" /// >set a(1,3,1)="ACA" /// >set a(2,1)="BA" /// >set a(3)="C" /// >set a(3,1)="CA" /// /// >write $$^Array2JSON(.a).%ToJSON() /// {"1":["A",{"1":["AA"],"2":["AB",{"1":["ABA"]}],# /// "3":[{"1":["ACA"]}]}],"2":[{"1":["BA"]}],"3":["C",{"1":["CA"]}]} /// /// I: &array: reference to the array /// /// O: JSON: %DynamicObject holding the indices as keys and node /// values and /// subnodes in %DynamicArrays Array2JSON(&array) Public { set JSON = ##class(%DynamicObject).%New() set key = $order(array("")) while ( key'="" ) { // create a new entry set subJSON = ##class(%DynamicArray).%New() if ( $get(array(key))'="" ) { do subJSON.%Push(array(key)) } if ( $order(array(key,""))'="" ) { kill subarray merge subarray = array(key) set subarrayJSON = $$Array2JSON(.subarray) do subJSON.%Push(subarrayJSON) } do JSON.%Set(key,subJSON) set key = $order(array(key)) } return JSON }
As Eduard Lebedyuk already wrote: If you want to work on a list you iterate through (esp. when removing entries) you best loop backwards.
Otherwise you will remove entries and later try to read them.
Regards
Matthias