2017-07-18 186 views
0

我將如何訪問值標籤以下JSON數組中訪問嵌套元素在JSON陣列

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

回答

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)

+0

所以我的陣列是不是JSON格式呢?對不起,我對此很新。我在JADE預處理器 – abhimalik

+0

中打印這個輸出,你的問題中提供的數據不是一個對象,也不是數組。如果GUID被標記爲字符串,那麼我們獲得有效數組,但是它有一個屬性名稱作爲JSON字符串(解析的是具有所需對象和屬性的數組),其值爲「」。 – meta4

+0

感謝您的幫助,但是這並不是我正在尋找的。永遠不要我感謝你的幫助和投入的時間。 – abhimalik