(这是我的模型方案:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "QuestionsModel",
"type": "array",
"items": {
"type": "object",
"properties": {
"section_name": { "type": "string" },
"options" : {
"type" : "array",
"items" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
}
这是映射模板:
#set($inputRoot = $input.path('$'))
[
#foreach($question in $inputRoot) {
"section_name" : "$question.section_name.S",
"options" : [
#foreach($items in $question.options.L) {
[
#foreach($item in $items.L) {
"$item.S"
}#if($foreach.hasNext),#end
#end
]
}#if($foreach.hasNext),#end
#end
]
}#if($foreach.hasNext),#end
#end
]
尽管此语法正确映射了数据,但它导致“选项”是一个空数组。
如果没有指定“选项”,那么我的 iOS 应用程序会收到有效的 JSON。但是,当我为“选项”尝试各种语法时,我要么得到无效的 JSON,要么得到“内部服务错误”,而 CloudWatch 的提供也好不到哪里去Unable to transform response
。
有效选项由以下内容填充:{L=[{"L":[{"S":"1"},{"S":"Dr"}]},{"L":[{"S":"2"},{"S":"Mr"}]},{"L":[{"S":"3"},{"S":"Ms"}]},{"L":[{"S":"4"},{"S":"Mrs"}]},{"L":[{"S":"5"},{"S":"Prof."}]}]}
由 Lambda 函数提供。
在这一点上,我只能得出结论,API Gateway VTL 不支持嵌套数组。