(這裏是我的模型方案:如何處理嵌套列表在AWS APIG映射模板中VTL
{
"$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網關VTL不支持嵌套數組。