2016-02-29 97 views
-1

我有一個複雜的嵌套JSON,我試圖解析/閱讀我的Javascript代碼,但不知道如何訪問這些對象。下面是JSON響應:訪問複雜的JSON對象

{ 
"the-revenant-original-motion-picture-soundtrack": { 
"uid": "fbde4e5c-e9f7-4d19-a1a3-8f3589ba1742", 
"title": "The Revenant (Original Motion Picture Soundtrack)", 
"genre": "Soundtrack", 
"classical": false, 
"tracks": [ 
    { 
    "fileName": "19-cat-mouse.mp3", 
    "title": "Cat & Mouse", 
    "artists": [ 
     "Ryuichi Sakamoto, Alva Noto & Bryce Dessner" 
    ], 
    "genre": "Soundtrack", 
    "album": "The Revenant (Original Motion Picture Soundtrack)", 
    "codec": "mp3", 
    "channels": "Stereo", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 19, 
    "trackLength": 342, 
    "diskNumber": 1 
    }, 
    { 
    "fileName": "20-the-revenant-main-theme-atmospheric.mp3", 
    "title": "The Revenant Main Theme Atmospheric", 
    "artists": [ 
     "Ryuichi Sakamoto" 
    ], 
    "genre": "Soundtrack", 
    "album": "The Revenant (Original Motion Picture Soundtrack)", 
    "codec": "mp3", 
    "channels": "Stereo", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 20, 
    "trackLength": 170, 
    "diskNumber": 1 
    }, 
    { 
    "fileName": "21-final-fight.mp3", 
    "title": "Final Fight", 
    "artists": [ 
     "Ryuichi Sakamoto & Bryce Dessner" 
    ], 
    "genre": "Soundtrack", 
    "album": "The Revenant (Original Motion Picture Soundtrack)", 
    "codec": "mp3", 
    "channels": "Stereo", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 21, 
    "trackLength": 395, 
    "diskNumber": 1 
    } 
] 
}, 


"twilight-of-the-ghosts": { 
"uid": "476fbe1a-1496-458e-9d3f-f11a8bffd74d", 
"title": "Twilight of the Ghosts", 
"classical": false, 
"tracks": [ 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-01-pinned-to-the-mattress.flac", 
    "title": "Pinned to the Mattress", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000411", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 1, 
    "trackLength": 274 
    }, 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-02-sinking-slowly-slowly-sinking.flac", 
    "title": "Sinking Slowly Slowly Sinking", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000412", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 2, 
    "trackLength": 270 
    }, 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-06-steamships-cross-the-desert.flac", 
    "title": "Steamships Cross the Desert", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000416", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 6, 
    "trackLength": 272 
    }, 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-07-time-tribe.flac", 
    "title": "Time Tribe", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000417", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 7, 
    "trackLength": 378 
    }, 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-08-how-did-they-find-me.flac", 
    "title": "How Did they Find Me?", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000418", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 8, 
    "trackLength": 290 
    }, 
    { 
    "fileName": "twilight-of-the-ghosts-twilight-of-the-ghosts-09-search-for-the-way-home.flac", 
    "title": "Search For The Way Home", 
    "artists": [ 
     "Twilight of the Ghosts" 
    ], 
    "album": "Twilight of the Ghosts", 
    "isrc": "USVDE1000419", 
    "codec": "FLAC 16 bits", 
    "channels": "2", 
    "bitsPerSample": 16, 
    "samplingRate": 44100, 
    "sequenceNumber": 9, 
    "trackLength": 281 
    } 
    ] 
} 
} 

我想訪問「的-亡魂,原來......」並顯示它和「 - 黃昏......」任何在主要對象的其他數據第一。還可以訪問與每個對象相關的「軌道」數據。有什麼建議麼 ?

+0

好嗎?什麼給你帶來麻煩? – Mathletics

+1

[以下是如何訪問屬性](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors)和[這裏是如何循環對象的鍵。]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)現在你已經擁有了完成這項工作的所有工具。 –

+0

@Mathletics:讓我們說主要對象是數據{....} ,所以訪問數據(0)或數據(1)不會給我「亡靈」或「暮光之城」,也不知道如何訪問它們。 – noobcoder

回答