我一直在努力构建一个 json 数组,但没有任何成功。对于有 json 经验的人来说,这对他来说是小菜一碟。
所以我想构造一个这样的json数组:
{
"M" : [ {id:"58893_1_M", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"L" : [ {id:"58893_1_L", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"XL" : [ {id:"58893_1_XL", value:"Ontario", imageFile:"58893_1.jpg"} ]
}
这是代码:
var totalObjects = new Array();
for (i = 0; i < roomQuotes.length; i++) {
var selectedClothe = {
index: []
};
var clotheId = some value;
var clotheQuantity = some value;
var clotheImage =some value;
selectedClothe.index.push({ "id": clotheId , "value": clotheQuantity , "imageFile": clotheImage });
totalObjects.push(selectedClothe);
}
但相反我有这个输出
{
"index" : [ {id:"58893_1_M", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"index" : [ {id:"58893_1_L", value:"Ontario", imageFile:"58893_1.jpg"} ] ,
"index" : [ {id:"58893_1_XL", value:"Ontario", imageFile:"58893_1.jpg"} ]
}
如何在索引变量中输入值?
谢谢你的帮助