[英]How to read an array in twig
I have an array of json composed this way : 我有以此方式组成的json数组:
[{"name":K,"age":14,"job":null}]
I want to know have to read it in twig. 我想知道必须细读它。 I've tried so many solution like those:
我已经尝试了很多解决方案,例如:
array|json_encode()
array|raw
{{ attribute(array, item) }}
But no one of those solutions are working 但是这些解决方案中没有一个在起作用
Thanks 谢谢
you can simply iterate the json without any preparements 您可以简单地迭代json而无需任何准备
[{"name":K,"age":14,"job":null},{"name":K,"age":17,"job":null}]
{% for key, value in array %}
{{ value.age ~ "-" }}
{% endfor %}
prints 14-17-
打印
14-17-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.