我正試圖檢索下面的JSON的「信息」部分。正如你可以在我的代碼中看到的,我使用如何檢索EJS中的對象內的對象
<%= person['person_details']%>
來檢索JSON的該部分。這返回[Object Object]。我想要做的是檢索JSON a.k.a的info部分中的所有內容:「jim」「bob」「true」和「兩個人走進酒吧,一個說:ow!」。一些JSON沒有相同的字段(我在下面添加了另一個示例)。我試過...
<%= person['person_details'][0][1]%>
但是,這會給出一個錯誤。如果我刪除[1],它會在我的下拉菜單中返回一個空數量。
<div class="personForm">
<form>
Select Parameters
<select id="personIdList">
<% data1.forEach(function(person) {%>
<option><%= person['person_details']%>
<% }); %></option>
</select>
</form>
</div>
//JSON THAT IM ATTEMPTING TO EXTRACT
"person_details": {
"info": {
"name": "Jim",
"lastName": "Bob",
"isMale": true,
"favJoke": "Two guys walk into a bar, one says: ow!"
}
},
//EXAMPLE 2
"person_details": {
"info": {
"email": "[email protected]",
"lastName": "tim",
"isMale": true,
"momMaidenName": "felicia"
}
},
//EXAMPLE 3 (info changes to information)
"person_details": {
"information": {
"email": "[email protected]",
"lastName": "tim",
"isMale": true,
"momMaidenName": "felicia"
}
},
'<%= person ['person_details'] ['info'] ['name']%> // Jim'?等等...... – Marcus
@Marcus'code <%= person ['person_details'] ['info']%>'作品並返回一個[Object Object],但... 'code <%= person ['person_details '] ['info'] ['name']%>'返回錯誤 – AnonUser
返回什麼*錯誤*? – Marcus