Possible Duplicate:
Dynamic object property name
$.ajax({
url: "ranktonumber.json",
dataType: "json",
success: function (data) {
// my problem is what should be in this line
}
});
Like you saw , i have jquery (ajax) command that give me json variable .
Let’s said that I have another variable called “rank” .
“rank” is the key of the json .
The json is :
{"Recruit":"1",
"Private":"2",
"Private*":"3",
"Private**":"4",
"Private***":"5",
"Corporal":"6",
"Corporal*":"7",
"Corporal**":"8",
"Corporal***":"9"}
how can i use “rank” in json , because that won’t work :
data.rank
If you didn’t understand yet , here is how i can do it in mirc :
$json(jsonvariable,rankvariable)
Use
data[rank]instead ofdata.rank