传递 JSON 数组 AWS API

问题描述 投票:0回答:1

我有这个模型 JSON 架构:

{
  "$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" }
        }
      }
    }
  }
}

我需要将此带有数组 ID 和内容的 Inarray 数组传递给 API AWS

而且我不知道这个inArray的格式是什么?:"?:

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

有这样的事吗?或者我必须创建一些特殊的数组并将其放入包含这两个数组的数组对象中:?

我得到的输出:是空的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
]
}
json amazon-web-services aws-lambda
1个回答
0
投票

您忽略了 $inputRoot 变量(这是速度模板)。

我想你会因为这样的事情而更快乐:

#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
]
}
© www.soinside.com 2019 - 2024. All rights reserved.