Javascript 在使用React Native解析RSS提要时,如何在description标记内获取description和imageUrl?

Javascript 在使用React Native解析RSS提要时,如何在description标记内获取description和imageUrl?,javascript,react-native,rss,rss-reader,Javascript,React Native,Rss,Rss Reader,这就是我试图解析的RSS提要中的项的样子: <item> <title> Former cop gets 18 years in prison for shooting civilian to death </title> <description> <![CDATA[ <a href="https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-sh

这就是我试图解析的RSS提要中的
项的样子:

<item>
<title>
Former cop gets 18 years in prison for shooting civilian to death
</title>
<description>
<![CDATA[
<a href="https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html"><img width=130 height=100 src="https://i-english.vnecdn.net/2019/11/30/phuoc146331574997301-157508140-8364-4799-1575086150_180x108.jpg" ></a></br>A Dong Nai court sentenced a former traffic policeman to 18 years in prison on Friday for fatally shooting a man in a family feud.
]]>
</description>
<pubDate>Sat, 30 Nov 2019 12:00:00 +0700</pubDate>
<link>
https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html
</link>
<guid>
https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html
</guid>
<slash:comments>0</slash:comments>
</item>

我正在尝试解析
描述
和嵌套在描述标记中的
图像URL
。我该怎么做?有什么建议吗?

使用jquery,您可以解析它并获取其中的所有字符串,如果您只需要最后一个字符串,您可以在节点名称列表中获取最后一个索引

    str = '<a href="https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html"><img width=130 height=100 src="https://i-english.vnecdn.net/2019/11/30/phuoc146331574997301-157508140-8364-4799-1575086150_180x108.jpg" ></a></br>A Dong Nai court sentenced a former traffic policeman to 18 years in prison on Friday for fatally shooting a man in a family feud.',
    html = $.parseHTML( str ),
    nodeNames = [];

    // Gather the parsed HTML's node names
    $.each( html, function( i, el ) {
        if(el.nodeName=='#text'){
            nodeNames[ i ] = el.nodeValue;
        }else{
            nodeNames[ i ] = el.innerText;
        }
    });
    console.log(nodeNames);

使用jquery,您可以解析它并获取其中的所有字符串,如果您只需要最后一个字符串,您可以在nodeNames列表中获取最后一个索引

    str = '<a href="https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html"><img width=130 height=100 src="https://i-english.vnecdn.net/2019/11/30/phuoc146331574997301-157508140-8364-4799-1575086150_180x108.jpg" ></a></br>A Dong Nai court sentenced a former traffic policeman to 18 years in prison on Friday for fatally shooting a man in a family feud.',
    html = $.parseHTML( str ),
    nodeNames = [];

    // Gather the parsed HTML's node names
    $.each( html, function( i, el ) {
        if(el.nodeName=='#text'){
            nodeNames[ i ] = el.nodeValue;
        }else{
            nodeNames[ i ] = el.innerText;
        }
    });
    console.log(nodeNames);

你确定解析器没有为你这样做吗?如果可能的话,你能给我看一下解析后的对象吗?但不是我想要的。而不是只解析
项的
说明
。它解析'19:28
Lorem ipsum诸如此类的废话`我只想让它解析
Lorem ipsum诸如此类的废话
partI相信它叫a![CDATA[tag是的,我确实明白你的意思,这是因为cdata标记实际上是这样的,但是如果你确定你总是在标记后面有文本,就像你提到的例子一样,你可以使用jQuery将其解析为html,你确定解析器不会为你这样做吗?如果可能的话,你可以向我展示解析过的对象,但不是我想要的方式仅解析
项的
描述
。它解析'19:28
Lorem ipsum blah blah`我只想解析
Lorem ipsum blah
部分我相信它被称为a![CDATA[tag是的,我确实明白你的意思,这是因为cdata标记实际上是这样的,但是如果你确定你总是在标记后面有文本,就像你提到的例子一样,你可以使用jquery将其解析为html。有一种方法可以实现这一点,而不使用jquery,因为我想我在某个地方读到过关于如何在React N中不使用jquery的内容ative(与DOM有关)。刚刚编辑过它parseHtml函数应该返回文本,credit:有没有办法不用jquery实现这一点,因为我想我在某个地方读到过关于如何在React Native(与DOM有关)中不使用jquery的内容。刚刚编辑过它parseHtml函数应该返回文本,credit:
    str = '<a href="https://e.vnexpress.net/news/news/former-cop-gets-18-years-in-prison-for-shooting-civilian-to-death-4020110.html"><img width=130 height=100 src="https://i-english.vnecdn.net/2019/11/30/phuoc146331574997301-157508140-8364-4799-1575086150_180x108.jpg" ></a></br>A Dong Nai court sentenced a former traffic policeman to 18 years in prison on Friday for fatally shooting a man in a family feud.',
    html = $.parseHTML( str ),
    nodeNames = [];

    // Gather the parsed HTML's node names
    $.each( html, function( i, el ) {
        if(el.nodeName=='#text'){
            nodeNames[ i ] = el.nodeValue;
        }else{
            nodeNames[ i ] = el.innerText;
        }
    });
    console.log(nodeNames);
function parseHTML(html) {
    var t = document.createElement('template');
    t.innerHTML = html;
    return t.content.cloneNode(true).textContent;
}