简体   繁体   English

rails 无法在 json 字段中存储 html

[英]rails unable to store html inside json field

I tried to create json and store it inside json field but all html tag gets change to some code我尝试创建 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()

after store it shows:-存储后显示:-

{"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"}

expected output:-预期输出:-

{"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"}

have you tried:你有没有尝试过:

# 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>"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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