2017-01-22 24 views
0

我有这个模型JSON模式:通JSON阵列AWS API

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "ArrayINPUT", 
    "type": "object", 
    "properties": { 
    "QueryID": { "type": "integer" }, 
    "nR": { "type": "integer" }, 
    "Inarray": { 
     "type": "array", 
     "items": { 
     "type": "object", 
     "properties": { 
      "ids": { "type": "integer" }, 
      "contents": { "type": "string" } 
     } 
     } 
    } 
    } 
} 

我需要这个Inarray阵列,阵列ID和内容传递给API AWS

,我不知道什么这个格式inArray ?:” :??

Inarray [0,"sdasd",1,"sdfsdfsdfdgfd",2,"asdjkfbfgbsdhbfhsdfbg"........] 

像这样的东西或我要创建一些特殊的阵列,并投入到这个数组对象至极包含此2 ARR AYS:?

输出我所得到的:为空Inarray

{ 
    "nR": "5", 
    "Inarray": [], 
    "QueryID": "" 
} 

我的JSON体映射模板:

#set($inputRoot = $input.path('$')) 
{ 
    "QueryID" : "$input.params('QueryID')", 
    "nR" : "$input.params('nR')", 
    "Inarray" : [ 
##TODO: Update this foreach loop to reference array from input json 
#foreach($elem in $input.params('Inarray')) 
{ 
    "ids" : "$elem.ids", 
    "contents" : "$elem.contents" 
    } 
#if($foreach.hasNext),#end 
#end 
] 
} 

回答

0

你忽略了$ inputRoot变量(这是一个Velocity模板)。

我想你会更开心W /像这样:

#set($inputRoot) = $input.path('$')) 
{ 
    "QueryID": "$inputRoot.QueryID", 
    "nR": $inputRoot.nR, 
    "Inarray": [ 
#foreach($elem in $inputRoot.Inarray) 
{ 
    "ids":$elem.ids, 
    "contents": "$elem.contents 
} 
#if($foreach.hasNext),#end 
#end 
] 
}