我有JSON数据作为查询的响应。然后最终用户从UI中做出两个选择,程序从JSON中检索数据。用户的选择存储在cityNumber
和selectParam
变量中。我想通过这两个变量作为关键。我可以通过中的cityNumber
,但selectParam
给出错误,因为没有任何键名为selectParam
。我如何通过动态传递selectParam
来检索数据?传递变量以获取JSON数据
var results = locations[cityNumber].data.selectParam.timeValuePairs;
'locations [cityNumber] .data [selectParam] .timeValuePairs'? – PeterMader