java - FreeMarker 模板错误:JSONArray 包装到 febStringModel
问题描述
我正在尝试将 JSON 对象发送到我的免费标记,但在测试 JUnit 时出现错误
这是我的对象
{
"filename": "test",
"orderId": "123435",
"orderDate": "23.09.2020г.",
"itemsCount": "4",
"items": [
{
"itemName": "ТВ Приставка 400",
"itemCount": "2 шт Х 400₽",
"itemSum": "800.00"
}
],
"totalSumm": "3000.00"
}
这是我的错误:
FreeMarker template error:
The value you try to list is an extended_hash+string (org.camunda.bpm.engine.impl.util.json.JSONArray wrapped into f.e.b.StringModel), thus you must specify two loop variables after the "as"; one for the key, and another for the value, like <#... as k, v>).
我该如何解决?
items 是 JSON 对象的数组
解决方案
FreeMarker 对 . 一无所知org.camunda.bpm.engine.impl.util.json.JSONArray
,因此它不会将其视为类似列表的事物(作为一个序列,因为它在 FTL 中被称为)。因此,您可以执行以下操作之一:
使用该
objectWrapper
Configuration
设置,您可以教 FreeMarker 如何将JSONArray
其视为列表。(您可以在其他地方找到有关 customObjectWrapper
-s 的更多信息。)然后您可以只#list
使用此类对象,并使用适用于序列的所有其他操作。JSONArray
或者,您从模板调用 Java API-s 。当然,这会不太方便,但不需要事先投资。
推荐阅读
- reactjs - 使用 react-testing-library 在 useEffect 中测试 api 调用
- javascript - Javascript:动态加载 JSON(取决于文件数量)
- debugging - 当 Visual Studio 调试器打开时,一些 Web Api 端点非常慢
- php - 在总小时列中的 mysql 中显示“小时”
- android - Android微调器下拉图标隐藏在背景图像下
- r - 将变量从因子更改为数字会更改顺序
- nginx - 如何命令 Nginx 停止重定向到其 404 页面?
- python - question_number = int(sys.argv[1]) IndexError: 列表索引超出范围
- vba - 如何以相同的格式将文本从一个文档复制到另一个文档?
- sql-server - SQL Server Management Studio:LocalDb 不显示