I have a json string like
{
"Msg1": "message 1",
"Msg2": "message 3",
"Msg3": "message 2"
}
我正在使用以下代码
function GetMessages(msg) {
$.getJSON("./jquery/sample.json", function (result) {
$.each(result, function (key, val) {
if (key == msg) {
alert(val);
}
});
}
有没有其他方法可以检查我的键是否存在于结果数组中并在不使用 foreach 循环的情况下获取它的值?eval() 可以做点什么吗?