1

如何在 Twig 中解码 JSON 数据这是我在控制器中的代码

public function testoutput($id) {
$form = $this->getDoctrine()
->getRepository(ApplicationForm::class)
->findAll();

return $this->render('testoutput.html.twig', array('form' => $form));}

我的数据库看起来像这样。

id |             jsonData             | dateSigned
===|================================= |============
1  | {"fname":"Jan", "lname": "Jake"} | 10-09-2019 
===|==================================|===========
2  | {"fname":"Mike", "lname": "Ham"} | 10-10-2019 
===|==================================|===========

我想在我的 Twig View 上显示这些数据,但我收到了这个错误

未知的“json_decode”过滤器。你的意思是“json_encode”吗?

我研究了这个错误,但似乎结果和代码已经过时了,大约 6 年前仍在使用 Symfony 2。Symfony 4.3 中的文件夹和结构已经是新的了。有什么新方法可以解决。

{% for data in form %}
{% set a = data.data_json | json_decode() %}

{% for json is a %}
    {{ json['fname'] }}
{% endfor %}

{% endfor %}
4

0 回答 0