2013-09-24 186 views
0

我有音頻文件元數據細節,如打擊json字符串。在這裏我需要過濾專輯和藝術家的歌曲。現在我正在使用循環過濾列表,但我有更多然後20​​00獨特的歌曲。我可以通過其他方式使用nodejs來做到這一點。json字符串填充nodejs

[{ 
"title":"Kallu Kollam - TamilWire.com", 
"picture":"Kallu Kollam - TamilWire.com", 
"artist":["N.D.Rajkumar"], 
"album":"Madhubaanakadai", 
"year":"2012", 
"path":"/media/data/songs/MadhuBana Kadai/Kallu Kollam - TamilWire.com.mp3" 
}, 
{"title":"Manjal Nira Bodhai - TamilWire.com", 
    "picture":"Manjal Nira Bodhai - TamilWire.com", 
    "artist":["N.D.Rajkumar"], 
    "album":"Madhubaanakadai", 
    "year":"2012", 
    "path":"/media/data/songs/MadhuBana Kadai/Manjal Nira Bodhai - TamilWire.com.mp3"}, 
.....] 
+1

商店他們在關聯數組的「索引」,使其通過的只需要循環整個數組構建結構並執行其他搜索。 – WiredPrairie

回答

2

集團使用下劃線庫按專輯數據:

var _ = require('underscore'); 

var songs = [{ 
"title":"Kallu Kollam - TamilWire.com", 
"picture":"Kallu Kollam - TamilWire.com", 
"artist":["N.D.Rajkumar"], 
"album":"Madhubaanakadai", 
"year":"2012", 
"path":"/media/data/songs/MadhuBana Kadai/Kallu Kollam - TamilWire.com.mp3" 
}, 
{"title":"Manjal Nira Bodhai - TamilWire.com", 
    "picture":"Manjal Nira Bodhai - TamilWire.com", 
    "artist":["N.D.Rajkumar"], 
    "album":"Madhubaanakadai", 
    "year":"2012", 
    "path":"/media/data/songs/MadhuBana Kadai/Manjal Nira Bodhai - TamilWire.com.mp3"} 
]; 

var grouped = _.groupBy(songs, function(song) {return song.album;}); 

凡分組將是:

{ 
    "Madhubaanakadai": [{ 
      "title":"Kallu Kollam - TamilWire.com", 
      ... 
     }, { 
      "title":"Manjal Nira Bodhai - TamilWire.com" 
      ... 
     } 
    ] 
} 
+0

謝謝..但在這裏我不知道專輯名稱或任何其他細節。 –

+0

我需要什麼獲得相同的song.album是否有可能 –

+1

好吧,我編輯了按專輯分組數據的答案。這是你想要的嗎? –