解析带有换行符的json并显示为HTML

Parsing json with newline character and displaying as HTML

本文关键字:显示 HTML json 换行符      更新时间:2023-09-26

我有一个JSON blob,它有一个换行符,采用转义形式。我想用换行符解析JSON blob,并在React中将其显示为HTML段落。

这可能吗?

代码:

var Blob = [{ "Content" : "HEHkspodjoisndjdsnsd ''n New Line here you go"}]
var TestClass = React.createClass({
    render:function() {
        return (
            <div>{this.props.test.Content}</div>
        );
    }
});
<TestClass test={Blob} />, document.getElementById('test');

这个库将使用标记非常好地呈现您的内容-它将''n识别为段落分隔符-您甚至可以在JSON blob中进一步创建更多的标记,以更深入地自定义显示。

https://github.com/rexxars/react-markdown