如何更换"阿根廷"用javascript变量字符串键?
jQuery(document).ready(function() {
$.getJSON('countries.json', function(data) {
var output= data.Argentina[0].countryPhone1;
alert(output);
});
});
这是我的.json数据文件的样子:
{
"Argentina": [{
"countryName":"Argentina",
"countryPhone1":"1234"
}],
"Brazil": [{
"countryName":"Brazil",
"countryPhone1":"5678"
}]
}
答案 0 :(得分:0)
var myString = 'Argentina'; /* or whatever you like */
var output = data[myString][0].countryPhone1;