【发布时间】:2021-09-29 23:54:50
【问题描述】:
我是 JSON 和 Twig 的新手。我能够将基本项目从 JSON 转换为 TWIG,但是当我到达数组部分时,我被卡住了。我尝试过不同类型的事情,但都不是很成功。第一个更复杂:
,所以我还没有对那个做任何事情(这是代码 sn-p 到目前为止试图显示的东西:
Freight List Item: <br>
Quantity: {{Result.FreightInformation.0.0.Item.Quantity}}<br>
Dim Type: {{Result.FreightInformation.0.0.Item.DimType}}<br>
Units: {{Result.FreightInformation.Item.0.0.Units}}<br>
Commodity: {{Result.FreightInformation.I0.0.tem.Commodity}}<br>
Weight: {{Result.FreightInformation.Item.0.0.Weight}}<br>
Length: {{Result.FreightInformation.Item.0.0.Length}}<br>
Width: {{Result.FreightInformation.Item.0.0.Width}}<br>
Height: {{Result.FreightInformation.Item.0.0.Height}}<br>
Class: {{Result.FreightInformation.Item.0.0.Class}}<br>
NMFC: {{Result.FreightInformation.Item.0.0.NMFC}}<br>
Hazmat: {{Result.FreightInformation.Item.0.0.Hazmat}}<br>
<br>
第二个不太复杂(所以我尝试了那个)但是有很多项目已经循环了:
我一直在研究,但现在我需要加快进度,因为等待我完成这项任务的人将考验他们的耐心。
Tracking Information<br>
{% for Result.TrackingInformation in Result.TrackingInformation %}
{% set counter = ( counter | default(0) ) + 1 %}
<p>{{ counter ~ ' ). ' Result.TrackingInformation.i.Item }}</p>
Person: {% for i in 0..100 %} {{Result.TrackingInformation.i.Item.Person}} {% endfor %}<br>
Code: {% for i in 0..100 %} {{Result.TrackingInformation.i.Item.Code}} {% endfor %}<br>
Status: {% for i in 0..100 %} {{Result.TrackingInformation.i.Item.Status}} {% endfor %}<br>
Remarks: {% for i in 0..100 %} {{Result.TrackingInformation.i.Item.Remarks}} {% endfor %}<br>
Date: {% for i in 0..100 %} {{Result.TrackingInformation.i.Item.date}} {% endfor %}<br>
Time:{% for i in 0..100 %} {{Result.TrackingInformation.i.Item.time}} {% endfor %}<br>
{% endfor %}
【问题讨论】:
标签: arrays json loops twig counter