通过字符串访问JSON成员? [英] Access a JSON member via string?
本文介绍了通过字符串访问JSON成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JSON:
json_filter = {"CO": "blah"}
我正在尝试通过字符串值访问成员'CO'.但是,结果是不确定的.
I am trying to access the member 'CO' by a string value. However, the result is undefined.
var selectedState = $(this).val();
// Selected 'CO'
console.log(json_filter.selectedState);
我当时以为eval()可能有效,但是eval()==魔鬼:)有更好的方法吗?
I was thinking eval() might work, but eval() == the devil :) Is there a better way to do this?
推荐答案
像这样:
console.log(json_filter[selectedState])
这篇关于通过字符串访问JSON成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文