jsonとjqueryを使用して投稿のリストを表示しようとしています。Jsonオブジェクト配列の値を取得する方法は?
これは、私がデータ
var app = {
init: function() {
app.getPosts();
},
getPosts: function() {
var rootURL = 'https://www.example.com/wp-json/wp/v2/posts';
$.ajax({
type: 'GET',
url: rootURL,
dataType: 'json',
success: function(data){
$.each(data, function(index, value) {
console.log(value.featured_image);
$('ul.topcoat-list').append('<li class="topcoat-list__item">' +
'<h3>'+value.title+'</h3>' +
'<p>'+value.excerpt+'</p></li>');
;
});
},
error: function(error){
console.log(error);
}
});
}
}
を取得するために使用していますものですが、このコードは、単に
を以下返しますが、私はhttps://www.example.com/wp-json/wp/v2/posts
に行くとき、私は完璧な配列を参照してください。
アレイの例が
{
"id":2267,
"type":"post",
"title":{"rendered":"When to visit Arugam Bay? – Arugam Bay Weather & Seasons \u2013"},
"content":{"rendered":"<div class=\"circle-headline\">\n<p>The right answer is<\/p>\n<\/div>\n<p class=\"wpk-circle-title text-custom\">ALL YEAR LONG!<\/p>\n<p>You can visit Arugam Bay anytime and always find amazing sunny weather. Despite this incredible where, there is a high and low season.<\/p>\n","protected":false},
"excerpt":{"rendered":"<p>The right answer is<\/p>\n<p>ALL YEAR LONG!<br \/>\nYou can visit Arugam Bay anytime and always find amazing sunny weather. Despite this incredible where, there is a high and low season.<\/p>\n","protected":false},
"author":1,
"featured_media":2268,
"comment_status":"open",
"ping_status":"open",
"sticky":false,
"template":"",
"format":"standard",
}
は、どのように私はそこからタイトルや抜粋を取得し、それを使用してリストを表示することができますか?
が...これはフラットなおっぱいを持っていることと思いますなぜ..なぜあなたはそれが好きではないのですか? –
ダウンボートするのは私ではありませんが、単純なデバッグロジックを書くことで、あなたの質問を簡単に解決できると思います。結果をデバッグするために 'console.log()'関数をもっと活用してください。 – Raptor