简体   繁体   中英

Parsing json with newline character and displaying as HTML

I have a JSON blob and it has a new line character which is in the escaped form. I want to parse the JSON blob with the newline character and display it as a HTML paragraph in React.

Is that possible?

Code:

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');

This library would render your content very nicely using markup - it recognizes \\n as a paragraph break - and you could even further create more markdown in your JSON blob to more deeply customize the display.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM