我有这样的JSON数组。
{"records":[{"ColorId":"3","ColorName":"Red","GenderId":"3","GenderName":"Female","SizeId":"1","SizeName":"N\/A"},{"ColorId":"2","ColorName":"Green","GenderId":"2","GenderName":"Male","SizeId":"1","SizeName":"N\/A"},{"ColorId":"3","ColorName":"Red","GenderId":"2","GenderName":"Male","SizeId":"1","SizeName":"N\/A"}]}
我需要将这些变量分成具有不同
的单独对象颜色:ColorId,ColorName
性别:GenderId,GenderName
大小:SizeId,SizeName
答案 0 :(得分:1)
这只是loop
的简单recods
,并在自己的结构中创建数据。甚至不需要使用任何jQuery函数。
for( var i = 0, l = data.records.length; i < l; i++ ) {
color.push({ColorId: data.records[i].ColorId, ColorName: data.records[i].ColorName});
gender.push({GenderId: data.records[i].GenderId, GenderName: data.records[i].GenderName});
size.push({SizeId: data.records[i].SizeId, SizeName: data.records[i].SizeName});
}
<强> Wokring example. 强>