如何用smarty生成json? [英] Howto generate json with smarty?

查看:153
本文介绍了如何用smarty生成json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Smarty中,是否有标准函数或简单的方法可以从数组生成json,就像json_encode()在php中一样?实际上,似乎没有精明的文档,但是无论如何都想问.

In Smarty, is there a standard function or an easy way to generate json from an array, as json_encode() does in php? Actually It seems there is not in smarty documentation but wanted to ask anyways.

谢谢, 思南.

推荐答案

这应该有效. @使聪明地针对整个数组运行修饰符,否则将对每个元素执行修饰符.

This should work. The @ makes smarty run the modifier against the whole array, otherwise it does it for each element.

{$myarray|@json_encode}

如果启用了 $ escape_html ,则需要使用nofilter:

If $escape_html is enabled, you will need to use nofilter:

{$myarray|@json_encode nofilter}

这篇关于如何用smarty生成json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆