3
From the TWIG documentaion about json_encode()
filter他們說:嫩枝json_encode多個選項
json_encode
的json_encode過濾器返回一個值的JSON表示:
{{ data|json_encode() }}
內部,嫩枝使用PHP json_encode功能。
參數
選項:的json_encode選項
({{data|json_encode(constant('JSON_PRETTY_PRINT')) }})
我試圖做的位掩碼是添加的這些選項多。
我想JSON_PRETTY_PRINT
和JSON_UNESCAPED_SLASHES
我已經試過
{{ array|json_encode(constant('JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES')) }}
{{ array|json_encode(constant('JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES')) }}
{{ array|json_encode(constant('JSON_PRETTY_PRINT', 'JSON_UNESCAPED_SLASHES')) }}
但他們沒有工作。我怎樣才能將TWIGs json_encode()
過濾器的兩個選項結合起來?
{% set array = {'xxx': "one", 'yyy': "two", 'path': "/hello/world" } %}
{% autoescape false %}
{{ array|json_encode() }}
{{ array|json_encode(constant('JSON_PRETTY_PRINT')) }}
{{ array|json_encode(constant('JSON_UNESCAPED_SLASHES')) }}
{% endautoescape %}
所需的輸出應該是
{
"xxx": "one",
"yyy": "two",
"path": "/hello/world"
}