我有json数据,我想从数据中获取特定的对象。在控制台中打印for (var key in data) {
console.log(data._embedded.artworks[0]._links.thumbnail);
}
时,我可以获得第一个缩略图。
我想知道如何获取所有缩略图。我尝试过
artworks[key]
但是在这里,我也只是从第一个ID获取缩略图。我尝试了_links
,但是无法访问json数据的其他方法,例如<link rel='stylesheet' id='gforms_formsmain_css-css' href='/wp-content/plugins/gravityforms/css/formsmain.min.css' type='text/css' media='all' />
<link rel='stylesheet' id='gforms_ready_class_css-css' href='/wp-content/plugins/gravityforms/css/readyclass.min.css' type='text/css' media='all' />
<link rel='stylesheet' id='gforms_browsers_css-css' href='/wp-content/plugins/gravityforms/css/browsers.min.css' type='text/css' media='all' />
<script type='text/javascript' src='/wp-content/plugins/gravityforms/js/jquery.json-1.3.js'></script>
<script type='text/javascript' src='/wp-content/plugins/gravityforms/js/gravityforms.min.js'></script>
。
我将如何遍历json数据以拔出所有缩略图?
答案 0 :(得分:3)
您正在遍历data
。您需要遍历data._emebedded.artworks
。试试:
var art = data._embedded.artworks;
art.forEach(function(o){
console.log(o._links.thumbnail);
});