rails 无法在 json 字段中存储 html

rails unable to store html inside json field

我尝试创建 json 并将其存储在 json 字段中,但所有 html 标签都更改为某些代码

 @vs=@tvrs.vsrs.new()
 @vs.jsr = ({"desc": "<html>\n<body>\n<ul>\n  <li>Generate client.</li>\n  <li>In every month. 
             </li>\n  \n</ul>  \n\n\n\n</body>\n</html>"})
 @vs.save()

存储后显示:-

{"id":11,"jsr":{"desc":"\u003chtml\u003e\n\u003cbody\u003e\n\u003cul\u003e\n  \u003cli\u003eGenerate client.\u003c/li\u003e\n  \u003cli\u003eIn every month.\u003c/li\u003e\n  \n\u003c/ul\u003e  \n\n\n\n\u003c/body\u003e\n\u003c/html\u003e"},"tvr_id":1,"created_at":"2020-06-12T04:01:16.116Z","updated_at":"2020-06-12T04:01:16.116Z"}

预期输出:-

{"id":11,"jsr":{"desc": "<html>\n<body>\n<ul>\n  <li>Generate client.</li>\n  <li>In every month. 
             </li>\n  \n</ul>  \n\n\n\n</body>\n</html>"},"tvr_id":1,"created_at":"2020-06-12T04:01:16.116Z","updated_at":"2020-06-12T04:01:16.116Z"}

你试过了吗:

# let's assume you have a @vs instance variable which has an attribute jsr.
JSON.parse(@vs.jsr)
=> {"desc": "<html>\n<body>\n<ul>\n  <li>Generate client.</li>\n  <li>In every month. </li>\n  \n</ul>  \n\n\n\n</body>\n</html>"}