访问复杂的 JSON 对象
Accessing complex JSON objects
我有一个复杂的嵌套JSON,我试图在我的Javascript代码中解析/读取它,但不确定如何访问这些对象。下面是 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
}
]
}
}
我想访问"亡魂原版..."并显示它和"暮光之城..."以及主对象中的任何其他数据。还可以访问与每个对象关联的"轨迹"数据。有什么建议吗?
将其粘贴到变量中
var example = { "jsonresponse": { ... } };
然后您可以通过以下方式访问它:
example.jsonresponse;
或
example["jsonresponse"];
您可能还想查看 JSON.parse() 和 JSON.stringify() https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON
相关文章:
- jQuery匹配JSON对象的部分文本
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- 我应该如何将响应数据保存在对象(json)中以获得更好的操作和性能
- 用javascript从列表对象(JSON的)构建diffrent选项卡
- php请求带有多个对象json-jquery
- AngularJS,过滤器:如何将一个巨大的对象(JSON)变成一个数组
- 动态属性对象 - JSON
- JavaScript 对象 (JSON) 中的动态设置值
- 从数组查询获取对象 JSON 值时出错
- 使用jQuerygetJSON将多维对象JSON转换为HTML
- 需要从 Angular JS 应用程序中的另一个 JSON 对象数组填充 JSON 数组的每个对象 JSON 对象数组
- 嵌套对象JSON排序JavaScript
- PHP在MySQL中保存来自Javascript的对象"JSON.stringify"通过Ajax
- 将JavaScript对象/ JSON转换为PHP数组
- JSON对象.JSON对象内部
- 访问对象的对象- JSON API
- 数组到对象JSON
- Message":"传入的无效对象(JSON数据格式化问题)