簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM