你需要處理對象本身。只有當您輸出對象或通過電線等方式發送對象時,才需要使用JSON.stringify
以可讀的格式顯示它們。
var ar = [{"url":"link1","title":"title1"}]
alert(ar); // equivalent to alert(ar.toString()), will show [object Object]
alert(JSON.stringify(ar)); // will show [{"url":"link1","title":"title1"}]
console.log(ar); // the proper way to do it, inspect the result in console
var playlist=[];
// then do either
playlist = playlist.concat(ar);
// or
playlist.push.apply(playlist, ar);
// or
playlist.push(ar[0]);
// or
playlist[0] = ar[0];
// or
playlist = ar;
// (which all do a little different things)
// but notice none of them used JSON.stringify!
// now you can
console.log(playlist)
alert(playlist[0].url); // shows link1 - this is what you want
alert(JSON.stringify(playlist[0].url)); // shows "link1"
你爲什麼要把所有東西串起來?只需傳遞'ar'對象! – Bergi
這是可以預料的,因爲您試圖以普通數組的形式訪問* stringified *數據 –
此外,您的播放列表只有一個項目,您可以通過「playlist [0]」訪問 - 數組爲零-索引。 – Bergi