我有以下JSON数据的变量。Json数据访问
var links = {
info: {
title: "Informatics "
},
busi: {
title: "Business"
},
lang: {
title: "Language"
}
};
在代码中,我有自己的变量命名的类型可能有串的信息,布丝,郎变量越来越像
function get_data(type)
{
var data = JSON.parse(links);
// Now i want to access the title of that particular type only I tried to use this but it didnt work
// data.type
// where as if i use the exact word it shows me data like this data.info
}
我想使代码更函数参数概括而不是坚持像信息,商业,土地等常数。任何建议如何使它更一般化?
请注意,您的问题无关,与JSON的属性。 JavaScript与JSON不同。 –
相关:[访问/进程(嵌套)对象,数组或JSON](http://stackoverflow.com/q/11922383/218196) –