使用动态键从json获取值 [英] get value from json with dynamic key
本文介绍了使用动态键从json获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的JScript是:
My JScript is:
var t={'color':'red'}; // dynamic json data.
for(n in t)
{
alert(n)
}
在这里,alert给出了json键颜色.但是如何获得它的价值?
here, alert gives the json key color. but how to get its value?
注意:json是动态的.
Note: the json is dynamic.
推荐答案
var t={'color':'red'}; // dynamic json data.
for(n in t)
{
alert(n);// n = key
var val =t[n];// value where key is n
}
这篇关于使用动态键从json获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文