私は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"} ]
}
インデックス変数に値を入れるにはどうすればよいですか?
助けてくれてありがとう