访问JSON数组中的嵌套元素

时间:2017-07-18 12:49:02

标签: json

如何访问以下JSON数组中的值标签

 [ { _id: 596e0053e405e523bca7d289,
'[{"type":"button","label":"Button","subtype":"button","className":"btn-
 default btn","name":"button-1500381266064","style":"de
 fault"}]': '' },
 { _id: 596e0053e405e523bca7d28a } ]

1 个答案:

答案 0 :(得分:0)

据我所知,你的JSON是属性的名称,鉴于GUID是以字符串形式提供的,这应该有效:

var t=[ { _id: '596e0053e405e523bca7d289',
'[{"type":"button","label":"Button","subtype":"button","className":"btn-default btn","name":"button-1500381266064","style":"default"}]': '' },{ _id: '596e0053e405e523bca7d28a' } ]

function propName(prop, value){
   for(var i in prop) {
       if (prop[i] == value){
            return i;
       }
   }
   return false;
}


console.log(JSON.parse(propName(t[0], ""))[0].label)

相关问题