2017-09-23 85 views
-1

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

var results = locations[cityNumber].data.selectParam.timeValuePairs;

+0

'locations [cityNumber] .data [selectParam] .timeValuePairs'? – PeterMader

回答

1

使用这样

变种结果=地点[cityNumber] [ “数据”] [selectParam] [ “timeValuePairs”];

+0

工作得很好,谢谢 – yalcinm1

+0

@ yalcinm1 upvote并接受答案,如果它有用。谢谢 – krishnar