首页 > 解决方案 > 以字符串形式检索 JSON 数据

问题描述

我在我的网站中使用 Draft.js 作为编辑器。我可以将编辑器文本保存为数据库中的 json 格式。但我想将 json 数据保存为字符串/Html,但它是以 json 格式出现的。到目前为止,这是我为将值保存为 json 格式所做的工作:

<Editor
    blockStyleFn={getBlockStyle}
    customStyleMap={styleMap}
    editorState={this.state.editorState}
    handleKeyCommand={this.handleKeyCommand}
    onChange={this.onChange}
    placeholder="Describe the requirements and skills needed for the job"
    ref="editor"
    spellCheck={true}
/>
<h4>Editor content as HTML</h4>
<pre>{this.state.editorContentHtml}</pre>

这是在编辑器下显示 html 代码的功能:

this.onChange = editorState => {
        this.setState({
            editorState,
            editorContentHtml: stateToHTML(editorState.getCurrentContent())

        });

    };

这是我的编辑器的快照

在此处输入图像描述 这是检索编辑器数据后的结果

这是检索编辑器数据后的结果

我想将 html 结果保存在数据库中,并将其显示为 html。如果有任何其他方法可以将数据检索为字符串格式,我们将不胜感激。

标签: jsonreactjspostgresqldraftjs

解决方案


推荐阅读