- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试访问此 url 可用的 json 中的“描述”:https://librivox.org/api/feed/audiobooks/id/11591/extended/1/format/json在 PhantomJS 脚本中。我的脚本只有一步:
steps = [
/*
* Step 1 - print out description
*/
function(){
page.open( 'https://librivox.org/api/feed/audiobooks/id/11591/extended/1/format/json' , function () {
var jsonSource = page.plainText;
//console.log( jsonSource );
var resultObject = JSON.parse(jsonSource);
var bookkey = Object.keys(resultObject.books);
console.log( bookkey );
console.log( resultObject.books.bookkey );
});
},
];
当我运行我的脚本时,我得到了这个输出:
14
undefined
我不确定我应该如何访问描述值。
这是来自上述 URL 的 json:
{"books":{"14":{"id":"11591","title":"Soldier Of The Legion; <br>An Englishman's Adventures Under The French Flag in Algeria And Tonquin","description":"An educated gentleman, Mr Manington has given an insight into the unusual experiences of an Englishman in the French Foreign Legion, such as no ordinary \"mercenary\" could have done. Most of the narrative deals with Tonquin, and the fighting there against the rebels in their forest fastnesses. Incidentally, in giving an account of his friendship for the native sergeant, Doy-Tho, the author has been able to impart to the pages of the book an Oriental atmosphere that we think will prove attractive to the reader. - Summary by Editors' Note","url_text_source":"http:\/\/www.gutenberg.org\/ebooks\/53902","language":"English","copyright_year":"1907","num_sections":"15","url_rss":"http:\/\/librivox.org\/rss\/11591","url_zip_file":"http:\/\/www.archive.org\/download\/\/a_soldier_of_the_legion_1702_librivox\/a_soldier_of_the_legion_1702_librivox_64kb_mp3.zip","url_project":"","url_librivox":"http:\/\/librivox.org\/a-soldier-of-the-legion-an-englishmans-adventures-under-the-french-flag-in-algeria-and-tonquin-by-george-manington\/","url_other":null,"totaltime":"07:56:47","totaltimesecs":28607,"authors":[{"id":"12503","first_name":"George","last_name":"Manington","dob":"1866","dod":"?"}],"url_iarchive":"http:\/\/archive.org\/details\/a_soldier_of_the_legion_1702_librivox","sections":[{"id":"392478","section_number":"0","title":"Dedication, Preface, Editors' Note","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_00_manington_128kb.mp3","language":"English","playtime":"316","file_name":"soldierlegion_00_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392479","section_number":"1","title":"Chapter 1 Ministere de la Guerre, The Recruiting Office, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_01_manington_128kb.mp3","language":"English","playtime":"3049","file_name":"soldierlegion_01_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392480","section_number":"2","title":"Chapter 2 General Inspection, The Band Of The Legion, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_02_manington_128kb.mp3","language":"English","playtime":"1923","file_name":"soldierlegion_02_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392481","section_number":"3","title":"Chapter 3 Part 1 Some Information Concerning Tonquin, Haiphong, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_03_manington_128kb.mp3","language":"English","playtime":"2561","file_name":"soldierlegion_03_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392819","section_number":"4","title":"Chapter 3 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_04_manington_128kb.mp3","language":"English","playtime":"2495","file_name":"soldierlegion_04_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392482","section_number":"5","title":"Chapter 4 Part 1 The Difficulties Of Obtaining Military Intelligence, Native spies, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_05_manington_128kb.mp3","language":"English","playtime":"2171","file_name":"soldierlegion_05_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"394973","section_number":"6","title":"Chapter 4 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_06_manington_128kb.mp3","language":"English","playtime":"2374","file_name":"soldierlegion_06_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392483","section_number":"7","title":"Chapter 5 Part 1 An execution, A Rebel Chieftan, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_07_manington_128kb.mp3","language":"English","playtime":"1860","file_name":"soldierlegion_07_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"395106","section_number":"8","title":"Chapter 5 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_08_manington_128kb.mp3","language":"English","playtime":"1835","file_name":"soldierlegion_08_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392484","section_number":"9","title":"Chapter 6 Part 1 La Soeur Agnes, Exeat, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_09_manington_128kb.mp3","language":"English","playtime":"2108","file_name":"soldierlegion_09_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"395107","section_number":"10","title":"Chapter 6 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_10__manington_128kb.mp3","language":"English","playtime":"2007","file_name":"soldierlegion_10__manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392485","section_number":"11","title":"Chapter 7 Part 1 The Last Struggles Of A Rebellion, Departure Of Captain Plessier, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_11_manington_128kb.mp3","language":"English","playtime":"1611","file_name":"soldierlegion_11_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"395159","section_number":"12","title":"Chapter 7 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_12_maningon_128kb.mp3","language":"English","playtime":"1306","file_name":"soldierlegion_12_maningon_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"392507","section_number":"13","title":"Chapter 8 Part 1 General Voyron, Organisation Of The Brigade, etc","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_13_manington_128kb.mp3","language":"English","playtime":"1673","file_name":"soldierlegion_13_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]},{"id":"395160","section_number":"14","title":"Chapter 8 Part 2","listen_url":"https:\/\/librivox.org\/uploads\/aradlaw\/soldierlegion_14_manington_128kb.mp3","language":"English","playtime":"1318","file_name":"soldierlegion_14_manington_128kb.mp3","readers":[{"reader_id":"6454","display_name":"David Wales"}]}],"genres":[{"id":"73","name":"War & Military"},{"id":"108","name":"Travel & Geography"}],"translators":[]}}}
最佳答案
从评论到回答。
尝试:resultObject.books[bookkey[0]]
这应该允许您调用 resultObject.books[bookkey[0]].description
。
享受吧。
注意
参见示例:https://jsfiddle.net/Twisty/fL129dnz/ & https://jsfiddle.net/Twisty/fL129dnz/3/
Objects.keys()
返回键数组。似乎某些浏览器可能接受包含单个元素的数组作为索引。对于这种情况,由于只调用了一本书,因此可以使用:resultObject.books[bookkey]
。为了更便携,我建议谨慎并定义单个结果:resultObject.books[bookkey[0]]
感谢@torazaburo 指出这一点。
关于javascript - 如何访问动态键下的json数据项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42774266/
我正在尝试弄清楚如何将一些数据从手机同步到 Android Wear 设备,并且我已经阅读了 developer.android.com 上关于数据项的文章,但是我仍然不清楚究竟如何使用它们。具体来说
$("selector").data("name", null); console.log($("selector").data("name")); 这将打印未定义。 有没有办法在元素的 jQuery
我使用 LINQ 从 CheckBoxList 控件中检索选中的项目: 这里是 LINQ: IEnumerable allChecked = (from ListItem item in Ch
在尝试为 C 堆栈构建测试平台时,我遇到了如何正确显示它的问题。我已经检查了六本书,它们都有一种将堆栈插入堆栈或从堆栈弹出的方法,但没有一本示例说明您如何实际使用这些例程。谁能告诉我模式,这样我就可以
我尝试在 AppEngine 中使用 urlfetch 将 POST 数据发送到服务器。其中一些 POST 数据项具有相同的名称,但具有不同的值。 form_fields = { "data":
我有以下情况(使用 KendoUI): 我有一个绑定(bind)到数据源的网格。当我在网格中选择一行时,我会调用其“change”事件来让所选的 dataItem e 通过其他 HTML 元素显示其值
我基本上是在构建一个快速而肮脏的类(class)目录,其中包含多个层次类别以及属于不同级别的这些类别的类(class)。 在旧的实现中,每个主要类别都有自己的 HTML 页面,与该类别相关的所有类(c
我是 MVC 和 ASP.NET 的新手,希望学习一些东西,所以我正在尝试制作一些简单的应用程序来学习来龙去脉。 好吧,我正在尝试让一个下拉框显示一个图书列表,它会在其中显示图书的标题,但会发布 bo
此行为导致我的项目出现问题。这是正在发生的事情的简化版本。我想了解为什么会发生这种情况,以及如何避免这种情况。我已将 vue 加载到我的网站头部: 这是 Vue 对象: vueObject = ne
我是一名优秀的程序员,十分优秀!