如何加载/生成JSON对象或像下面的对象数组
var players = [
{"name":"John", "startPoint":"3", "maxPoint":"80"},
{"name":"Anna", "startPoint":"6", "maxPoint":"28"},
{"name":"Peter", "startPoint":"6", "maxPoint":"80"},
{"name":"Zack", "startPoint":"2", "maxPoint":"65"},
{"name":"Andy", "startPoint":"4", "maxPoint":"80"},
{"name":"Mick", "startPoint":"0", "maxPoint":"65"},
{"name":"Robin", "startPoint":"2", "maxPoint":"80"},
{"name":"Ed", "startPoint":"5", "maxPoint":"28"},
{"name":"Chris", "startPoint":"1", "maxPoint":"65"},
{"name":"Lee", "startPoint":"3", "maxPoint":"80"},
{"name":"Baron", "startPoint":"6", "maxPoint":"65"},
{"name":"Sam", "startPoint":"1", "maxPoint":"80"}
];
从三个JavaScript Array Object中:
var members = ["John","Anna","Peter","Zack","Andy","Mick","Robin","Ed","Chris","Lee","Baron" ,"Sam" ]
var startPoint = [3, 6, 6, 2, 4, 0, 2, 5, 1, 3, 6, 1];
var maxPoint =[80, 28, 80, 65, 80, 65, 80, 80, 65, 80, 65, 80];
答案 0 :(得分:2)
var result = [], i;
for (i = 0; i < members.length; ++i) {
result.push({name: members[i], startPoint: startPoint[i], maxPoint: maxPoint[i]});
}
return JSON.stringify(result);