[英]Draft.js Cannot convert undefined or null to object convertFromRaw
I save my html code to sql database as json format 我将html代码以json格式保存到sql数据库
const content = this.state.editorState.getCurrentContent();
const raw = JSON.stringify(convertToRaw(content))
raw is 原始是
{"entityMap":{},"blocks":[{"key":"4bk88","text":"ridee","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]}
{“ entityMap”:{},“ blocks”:[{“ key”:“ 4bk88”,“ text”:“ ridee”,“ type”:“ unstyled”,“ depth”:0,“ inlineStyleRanges”:[] ,“ entityRanges”:[],“ data”:{}}]}
however when I send it with XMLHTTPRequest in the server it changes req.body become to 但是,当我在服务器中使用XMLHTTPRequest发送它时,它将req.body更改为
post.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
This is how it saves 这就是节省的方式
{"{\\"entityMap\\":{},\\"blocks\\":[{\\"key\\":\\"Some Text\\",\\"text\\":\\"ridee\\",\\"type\\":\\"unstyled\\",\\"depth\\":0,\\"inlineStyleRanges\\":":[""]}
{“ {\\” entityMap \\“:{},\\” blocks \\“:[{\\” key \\“:\\” Some Text \\“,\\” text \\“:\\” ridee \\“,\\” type \\“ :\\“ unstyled \\”,\\“ depth \\”:0,\\“ inlineStyleRanges \\”:“:[”“]}
so after I recieve it does not return as the expected object 所以我收到后不会返回预期的对象
const raw = JSON.parse(req.response.htmlcode)
const contentState = convertFromRaw(raw);
{"entityMap":{},"blocks":[{"key":"Some Text","text":"ridee","type":"unstyled","depth":0,"inlineStyleRanges": :
{“ entityMap”:{},“ blocks”:[{“ key”:“ Some Text”,“ text”:“ ridee”,“ type”:“ unstyled”,“ depth”:0,“ inlineStyleRanges”::
I get this as expected however convertFromRaw gives this error 我得到了预期的结果,但是convertFromRaw给出了此错误
Cannot convert undefined or null to object
无法将未定义或null转换为对象
Object.keys(entityMap).forEach(function (storageKey)
Object.keys(entityMap).forEach(函数(storageKey)
Thanks in advance! 提前致谢!
我以错误的格式发送到服务器,我已将application / x-www-form-urlencoded更改为application / json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.