3 回答

TA貢獻1784條經驗 獲得超9個贊
"education_and_career"
是一個包含 JSON 字符串的字段,因此您不能像普通數組一樣使用它。但是,您可以使用該JSON.parse
方法來解析它。所以為了訪問 hieghest_education 領域,你會這樣做:
JSON.parse(data.education_and_career)[0].highest_education

TA貢獻1802條經驗 獲得超6個贊
您需要將 education_and_career 屬性解析為 JSON。下面是帶有 map 函數或 for 循環的示例
var data = {
"members": [{
"member_id": "1",
"first_name": "John",
"last_name": "Doe",
"education_and_career": "[{\"highest_education\":\"MSc\",\"occupation\":\"Lead Developer\",\"annual_income\":\"100,000 USD\"}]",
}]
};
var parsed=data.members.map(i=>JSON.parse(i.education_and_career));
console.log("parsed",parsed)
for (i = 0; i < data.members.length; i++) {
console.log(JSON.parse(data.members[i].education_and_career))
}

TA貢獻1802條經驗 獲得超5個贊
看起來education_and_career
不是對象數組。您需要使用 String.replace() 方法刪除 \ 并將其轉換為 JSON 數據,您將能夠訪問 highest_education 值,如 education_and_career[0].highest_enducation_value 等。
添加回答
舉報