yesod中如何将Json转换为Html?

发布于 2024-12-18 05:03:01 字数 327 浏览 2 评论 0原文

yesod-0.9.3 中是否有某种方法可以将 Json 转换为 Html 以将其包含到

使用 Yesod.JsonData.Aeson 我可以获得 Json 类型的值,我想将其用作变量的值在

Is there some way in yesod-0.9.3 to convert Json to Html to include it into <script/> tag?

Using Yesod.Json and Data.Aeson I can get the value of a Json type, which I want to use as the value of a variable introduced in a <script> tag, that is, not to return RepJson, but to include it as a part of RepHtml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是伱的 2024-12-25 05:03:01

使用完全限定名称...

let txtVal = Data.Text.Lazy.Encoding.decodeUtf8 $ Data.Aeson.encode jsonVal

然后,在您的小村庄内:

<script>
  var v = #{txtVal}

请注意,这有点危险,因为它不会检查编码是否成功。有关详细信息,请参阅 Data.Text.Encoding 模块。

Using fully qualified names...

let txtVal = Data.Text.Lazy.Encoding.decodeUtf8 $ Data.Aeson.encode jsonVal

then, inside your hamlet:

<script>
  var v = #{txtVal}

Note that this is a bit dangerous in that it doesn't check that the encoding was successful. Look at the Data.Text.Encoding module for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文