This question already has answers here:
Dynamically access object property using variable
(14个回答)
4年前关闭。
所以我在解决如何在流星应用程序中以JSON点表示法引用变量时遇到问题。在执行respJson.userlower.name时,userlower未被识别为变量。反正有解决这个问题的方法吗?我需要使用userlower作为变量的原因是因为它正在传递到此函数中并包含用户名。我得到的JSON数据返回如下:
(14个回答)
4年前关闭。
所以我在解决如何在流星应用程序中以JSON点表示法引用变量时遇到问题。在执行respJson.userlower.name时,userlower未被识别为变量。反正有解决这个问题的方法吗?我需要使用userlower作为变量的原因是因为它正在传递到此函数中并包含用户名。我得到的JSON数据返回如下:
{"tiandi":{"id":19888066,"name":"Tiandi","profileIconId":7,"summonerLevel":30,"revisionDate":1416925919000}}
try {
var result = HTTP.get(url, function(err, result){
console.log(result);
if (result.statusCode == 200) {
var userlower = userName.toLowerCase();
var respJson = JSON.parse(result.content);
console.log("response received.");
GameList.insert({
IGN: respJson.userlower.name,
level: respJson.userlower.summonerlevel,
Game: "League of Legends"
});
}
});
} catch (e) {
console.log(e);
}
最佳答案
括号符号:
respJson[userlower].summonerlevel,
10-04 22:16