简体   繁体   中英

Array of objects using IODOCS

I want to add a Array of object like

    "identifiers": [
      {
        "primary": true
       },
       {
        "primary": false
       },
     ]

But the object inside array always need a name to create like

    "identifiers": [
       {
         "IDENTIFIER": {
             "primary": true
         }
       }
     ]

I used the following JSON code in config file,

    "identifiers": {
        "title": "Identifiers",
        "type": "array",
        "location": "body",
        "items": {
            "title": "Identifier Fields",
            "type": "object",
            "properties": {
                "IDENTIFIER": {
                    "type": "object",
                    "properties": {
                        "primary": {
                            "title": "primary",
                            "required": true,
                            "type": "boolean",
                            "description": "",
                            "default": true
                        }
                    }
                }
            }
        }
    }

How to achieve this. Kindly help me.

Thanks in advance.

you can do like this

data =  {"identifiers": [
      {
        "primary": true
       },
       {
        "primary": false
       },
     ]};

for(i=0;i<data.identifiers.length;i++) {
    obj = data.identifiers[i];
    obj =  {
         "IDENTIFIER": {
             "primary": obj.primary
         }
       }

//if you want all properties of obj means you have loop through it create them. go through this copying properties }

Thanks for responses.

I have made a mistake by adding extra object parameter. I have fix it by removing the extra object like

"identifiers": {
    "title": "Identifiers",
    "type": "array",
    "location": "body",
    "items": {
        "title": "Identifier Fields",
        "type": "object",
                "properties": {
                    "primary": {
                        "title": "primary",
                        "required": true,
                        "type": "boolean",
                        "description": "",
                        "default": true
                    }
                }
            }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM