使用液体和变量从JSON对象获取字段
我正在尝试使用液体模板创建推送通知,但不知道如何从JSON中提取特定字段。
我有一个创建液体对象的JSON {%分配对象=响应|替换:'=>',':'| JSON_PARSE%}
JSON看起来像这样:
[
{
"en": "Hello!:",
"sv": "Hej!"
}
]
我可以使用:{{object [0] .en}}
会给我“ Hello hello”
,但是我有语言存储在称为语言
的变量中,我不想对语言进行编码。
取而代之的是,我想使用变量语言
获取正确的值,但我无法使其工作。我已经尝试了以下内容:
{{object[0]['${language}']}}
{{object[0][${language}]}}
{{object[0].${language}}}
{{object[0].'${language}'}}
有什么想法如何使用我的Lakenagent
变量在JSON对象中获取正确的值?
edit :我想知道我需要在双卷发括号前添加空白空间,然后它的工作原理 {{object [2] [$ {MOST_RECENT_LOCALE}]}}}
I'm trying to create a push notification using a Liquid template but don't know how to extract a specific field from the json.
I have a json which I create an Liquid object{% assign object = response | replace: '=>', ':' | json_parse %}
The json looks like this:
[
{
"en": "Hello!:",
"sv": "Hej!"
}
]
I can access the field using: {{object[0].en}}
which will give me "Hello"
However, I have the language stored in a variable called language
and I don't want to hardcode the language.
Instead, I would like to use the variable language
to fetch the correct value but I can not get it to work. I have tried the below:
{{object[0]['${language}']}}
{{object[0][${language}]}}
{{object[0].${language}}}
{{object[0].'${language}'}}
Any ideas how I can fetch the correct value based in the json object using my language
variable?
edit: I figure out that I needed to add a blankspace after an before the double curly brackets, then it works perfect e.g{{ object[2][${most_recent_locale}] }}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论