[{
"school_id": "248",
"server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/",
"school_id_string": "jayanagar",
"logo_path": "0",
"about": "all"
}]
如何檢索的價值學校ID在JS?
[{
"school_id": "248",
"server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/",
"school_id_string": "jayanagar",
"logo_path": "0",
"about": "all"
}]
如何檢索的價值學校ID在JS?
是雙向
let data = [{"school_id":"248","server_url":"http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/","school_id_string":"jayanagar","logo_path":"0","about":"all"}];
之一:
data[0].school_id
data[0]['school_id']
您可以使用此:
let data = [{
"school_id": "248",
"server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/",
"school_id_string": "jayanagar",
"logo_path": "0",
"about": "all"
}];
console.log(data[0].school_id); // use this if just one object in array
console.log(`-----------------------------------------------`)
data.forEach(o=>console.log(o.school_id)); // use this if more than one objects in array
如果您的數組中有一個對象,那麼你可以針對它的[0]
th索引來獲得目標對象的期望屬性。否則,如果有多個對象,則必須遍歷每個對象。
這將讓你從你的JSON的schoolid
var t = JSON.parse('{"school_id": "248", "server_url": "http:\/\/testdummy.brainyknights.in\/AndroidAppv5\/", "school_id_string": "jayanagar", "logo_path": "0", "about": "all"}');
alert(t['school_id'])
謝謝你。代碼正在工作 – priya