0

当我在 json 数据的 rails 中使用 strip_tags 剥离 html 标签时,它返回错误的数据:

the original data is: "<p><em><span style=\"font-size: 96px; \">test</span></em></p>"
data.to_json is: "\"<p><em><span style=\\\"font-size: 96px; \\\">\\u9ed1\\u4f53\\u5b57\\u54e6</span></em></p>\""
the stripped data that after strip_tags is: "\""

谁能告诉我原因或其他解决方案?

4

1 回答 1

0

将顺序更改为:

strip_tags(data).to_json

您将按预期获得“测试”。

原因是 html-scanner(由 strip_tags 使用)剥离了编码的“测试”值。

于 2011-11-09T16:12:55.953 回答