【问题标题】:Parsing json with newline character and displaying as HTML使用换行符解析 json 并显示为 HTML
【发布时间】:2016-04-15 20:55:38
【问题描述】:

我有一个 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');

【问题讨论】:

    标签: javascript json reactjs


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2013-04-20
      相关资源
      最近更新 更多