我有JSON数据
var obj=fields: {
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsInStock: { type: "number" },
Discontinued: { type: "boolean" }
.
.
.
n number of properties
}
我的实际问题是,字段可以有n个属性。任何人都可以帮助我。
提前致谢
答案 0 :(得分:0)
你可以循环它:
var obj = {
fields: {
ProductName: {
type: "string"
},
UnitPrice: {
type: "number"
},
UnitsInStock: {
type: "number"
},
Discontinued: {
type: "boolean"
}
}
};
var n = 100;
for (var i = 0; i < n; i++) {
obj.fields["prop" + i] = {type: "string"};
}
console.log(obj);