2016-02-29 72 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

回答