2

U2/Universe JSON document have the following UDOSetProperty, how would one set the value if it has multiple values? For example if I have multiple emails.

example: UDOSetProperty(udoHandle, "to", value)

 "to": [
        {
            "email": "recipientEmail@example.com",
            "name": "Recipient Name",
            "type": "to"
        }
    ],

1 Answers1

3

Not sure if you are trying to add another "to" array element or if you want to add a 2nd "email" only.

So working with your example:

"to": [
        {
            "email": [ "recipientEmail@example.com",
            "name": "Recipient Name",
            "type": "to"
        },
        {
            "email": [ "recipient2Email@example.com",
            "name": "Recipient2 Name",
            "type": "to"
        }
 ],

If you wanted to create the above JSON from scratch, with the UDO commands, the steps would be:

Using the following functions should help you with what you are trying to do:

  1. Create the initial/root object UDOCreate(UDO_OBJECT, udoHandle)

  2. Create the array UDOCreate(UDO_ARRAY, thisArray)

  3. ( Use UDOCreate and UDOSetProperty to create the theEmailObject you want to add to the array, and then add it to the object with
    UDOArrayAppendItem( thisArray, theEmailObject )

  4. Then add the array to the root object eith UDOSetProperty(udoHandle, "TO", thisArray)

Note the part that is important is that there are several functions for dealing with arrays.

Mike

Created a program that builds the JSON with the U2 UDO functions, and added it to github: https://github.com/RocketSoftware/multivalue-lab/blob/master/U2/Demos/UDO/JSON/The-Basics/arrayExample

JamsJordn
  • 3
  • 2
Mike
  • 194
  • 11
  • Quick question Mike, the UDOSetProperty, all it does is escaping a string by insert \ before the " right? So basically, anywhere it sees the " this will become \", Is that correct? – user3464522 Apr 12 '14 at 15:47
  • To be honest, I have not checked to see if there were other characters that are escaped. Yet you are correct about the '"' becoming '\"' when written out to a JSON string. – Mike Apr 14 '14 at 15:15