我试图设置JSON对象属性的值,但是当我运行
Object.property = value
整个JSON对象将替换为字符串
229,
for(var i=0; i<config["profiles"].length; i++){
profile = config["profiles"][i];
out = {
"name":profile["name"],
"version":profile["version"].replace(/_/g, "."),
"mods":null,
"saves":null
}
console.log(out)
out.mods = getMods(profile);
console.log(out)
console.log(getSaves(profile))
out.saves = getSaves(profile);
console.log(out)
profiles.push(out);
}
return profiles;
前2名
console.log(out)
调用按预期返回正确的JSON对象。
console.log(getSaves(profile))
打印以下内容:
[ { name: 'Hard Career ',
mode: 'CAREER',
funds: '275,520',
science: '229',
reputation: '721',
flights: '20' },
{ name: 'Sandbox ',
mode: 'SANDBOX',
funds: 0,
science: 0,
reputation: 0,
flights: '12' } ]
但是,打印后
out.saves = getSaves(profile)
打印以下内容:
229,
.
更复杂的是,这只发生在
config["profiles"]
数组。
提前谢谢!