私はGoogleアラートでアラートを作成し、XMLを解析する必要があります。私はfeed-reader
モジュールを使用していますし、私のコードは以下の通りです:JSONを反復処理すると、最後の結果のみが返されます
app.get('/', (req, res) => {
parse(url).then((rss) => {
let title,
link,
publishedDate,
contentSnippet = '';
let json = {};
rss['entries'].forEach((item) => {
title = item.title;
link = item.link.substring(42, item.link.indexOf('&ct='));
publishedDate = item.publishedDate;
contentSnippet = item.contentSnippet;
});
json = {
title,
link,
publishedDate,
contentSnippet
};
res.send(beautify(json, null, 2, 100));
}).catch((err) => {
res.send(err);
});
});
私は"entries"
キーの内側に何をループしたいと思います。それは動作しますが、結果は最後になります。
また、json
変数をループ内に移動すると、正しい長さではあるが、返される結果はになります。
私はJSON.stringify
を試しましたが、違いはありません。
console.log jsonオブジェクトres.sendの前に貼り付けて、ここに貼り付けてください –