2016-03-03 20 views
0

(這裏是我的模型方案:如何處理嵌套列表在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不支持嵌套數組。

回答

0

AWS iOS的SDK建模不支持數組的數組。

你必須定義在任何嵌套陣列之間的字典。 所以不是陣列/對象/數組/數組你一個額外的「awshack」對象滑:數組/對象/數組/ awshack對象/數組

{ 
"$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" : "object", 
          "properties" : { 
           "awshack" : { 
            "type" : "array", 
            "items" : { "type" : "string" } 
           } 
          } 
        } 

     } 
    } 
} 
} 

在映射模板中的「awshack」中下滑在最內層循環之外。

#foreach($items in $question.options.L) 
    {"awshack" : 
     [#foreach($item in $items.L) 
      "$item.S"#if($foreach.hasNext),#end 
     #end 
    #if($foreach.hasNext),#end 
]}#if($foreach.hasNext),#end 
#end 

Amazon confirms this limitation