Possible Duplicate:
Dynamic object property name
$.ajax({
url: "ranktonumber.json",
dataType: "json",
success: function (data) {
// my problem is what should be in this line
}
});
就像你看到的,我有 jquery (ajax) 命令给我 json 变量。 假设我有另一个名为“rank”的变量。 “rank” 是 json 的键。 json 是:
{"Recruit":"1",
"Private":"2",
"Private*":"3",
"Private**":"4",
"Private***":"5",
"Corporal":"6",
"Corporal*":"7",
"Corporal**":"8",
"Corporal***":"9"}
我如何在 json 中使用“rank”,因为那不起作用:
data.rank
如果您还不明白,以下是我如何在 mirc 中做到这一点:
$json(jsonvariable,rankvariable)
最佳答案
使用data[rank]
而不是data.rank
关于javascript - js - 获取带有变量的json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12330187/