我想添加一个对象数组,如下所示
"identifiers": [
{
"primary": true
},
{
"primary": false
},
]但是数组中的对象总是需要一个名称才能创建
"identifiers": [
{
"IDENTIFIER": {
"primary": true
}
}
]我在配置文件中使用了以下JSON代码,
"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
}
}
}
}
}
}如何实现这一点。请帮帮我。
提前谢谢。
发布于 2015-08-17 15:08:36
你可以这样做
data = {"identifiers": [
{
"primary": true
},
{
"primary": false
},
]};
for(i=0;i<data.identifiers.length;i++) {
obj = data.identifiers[i];
obj = {
"IDENTIFIER": {
"primary": obj.primary
}
}//如果你想要obj的所有属性,意味着你要遍历它,创建它们。通过此copying properties }
发布于 2015-08-17 15:36:50
感谢您的回复。
我犯了一个错误,添加了额外的对象参数。我已经通过移除额外的对象来修复它,比如
"identifiers": {
"title": "Identifiers",
"type": "array",
"location": "body",
"items": {
"title": "Identifier Fields",
"type": "object",
"properties": {
"primary": {
"title": "primary",
"required": true,
"type": "boolean",
"description": "",
"default": true
}
}
}
}https://stackoverflow.com/questions/32044525
复制相似问题