How to parse/decode JSON object in smarty template?

﹥>﹥吖頭↗ 提交于 2019-12-01 05:42:51

JSON string is just string. To access its members you have to create array/object from this string:

{foreach from=$items item=entry}
  {* create array from JSON string*}
  {assign var=person value=$entry->nb_persons|json_decode:1}
  <pre>
    {$person.company}
  </pre>
{/foreach}

I'm not an expert with Smarty, but I think you're trying to access the property of a JSON structured string.
Try to decode it first to an object and then access it.

Something like this:

{foreach $items as $entry}
  {assign var="person" value="{$entry->nb_persons|@json_decode}"}
  <pre>
    {$person.company}
  </pre>
{/foreach}

I didn't test it, though.

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!