【发布时间】:2019-07-16 01:21:24
【问题描述】:
我希望将变量插入到对象键结构中,但我只得到变量名而不是变量值。
var winnerId = 10;
var loserId = 11;
newMessage.setMessageData({
winnerId : {
"status" : "win",
"choice" : playerData[winnerId]["currentChoice"],
"newScore" : playerData[winnerId]["score"]
},
loserId : {
"status" : "lost",
"choice" : playerData[loserId]["currentChoice"],
"newScore" : playerData[loserId]["score"]
}
});
【问题讨论】:
-
我觉得自己有点破纪录,但指出您所描述的内容与 JSON 无关,总是感觉有用。它只是一个普通的旧 object。 JSON 是一个
string,它表示一个对象。 -
很高兴知道谢谢。我相信它已经说过很多次了:-)
标签: javascript