0
我想獲取職位及其相關數據,如區域和分區。我的JSON在這裏如何使用JavaScript在JSON中獲取類別及其相關數據
{ "data":[{"IT_JOBS":{ "areas": [ "SE", "QA","PM"],"subareas":["Associate","Trainee","Developer"] },..}] }
我想獲取職位及其相關數據,如區域和分區。我的JSON在這裏如何使用JavaScript在JSON中獲取類別及其相關數據
{ "data":[{"IT_JOBS":{ "areas": [ "SE", "QA","PM"],"subareas":["Associate","Trainee","Developer"] },..}] }
如果你想擁有一個對象數組,你需要修改你的數據。
{
"data":[
{
"name": "IT_JOBS",
"areas":[
"SE",
"QA",
"PM"
],
"subareas":[
"Associate",
"Trainee",
"Developer"
]
},
{
"name": "IT",
"areas":[
"SEs",
"QsA",
"PMs"
],
"subareas":[
"Assocsasdiate",
"Traineeasd",
"Developeasdasdr"
]
}
]
}
以下是樣本Jsfiddle。
for (var key in response.data) {
var obj = response.data[key];
console.log("Values for ITEM: " + key)
console.log("Name: " + obj.name);
console.log("Areas: " + obj.areas);
console.log("Subareas: " + obj.subareas);
}
如果你有一個對象,你可以做這樣的事情Jsfiddle。
for (let i = 0; i < response.data.length; i++) {
console.log("Values for IT_JOBS");
console.log("Areas: " + response.data[i].IT_JOBS.areas);
console.log("Subareas: " + response.data[i].IT_JOBS.subareas);
}
謝謝你。這是我的預期。非常感謝 – madhev
你可以附上一個plnkr嗎? – Deepanjan
好的,你有什麼嘗試? – Esko
@Esko我用於循環。如何獲得價值「IT_JOBS」? – madhev