gpt4 book ai didi

json - AWS Lambda 错误 : 'Could not parse request body into json ' when url parameter contains JSON array

转载 作者:行者123 更新时间:2023-12-04 20:01:03 25 4
gpt4 key购买 nike

我正在尝试调用我的 Lambda 函数通过传递参数如下。它包含 撇号(') .

https://invoke_url?param=[["kurlo jack's book","Adventure Books",8.8,1]]

字符串化为 ' https://invoke_url?param=%5B%5B%229780786706211%22s ....`

我使用下面的映射将参数传递给 lambda

  "query": {
#foreach($queryParam in $input.params().querystring.keySet())
"$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end

#end
}


我收到以下错误
{"message": "Could not parse request body into json: Unrecognized character escape \'\'\' (code 39)\n at [Source: [B@5b70c341; line: 29, column: 65]"}  

从映射模板中删除双引号后,我也尝试过。但没有奏效。

最佳答案

一定要加.replaceAll("\\'","'")到您的请求正文传递模板 .escapeJavaScript(data) 之后

我发现 AWS 文档中的这一点对这个问题非常有帮助:

$util.escapeJavaScript()

Escapes the characters in a string using JavaScript string rules.

Note This function will turn any regular single quotes (') into escaped ones (\'). However, the escaped single quotes are not valid in JSON. Thus, when the output from this function is used in a JSON property, you must turn any escaped single quotes (\') back to regular single quotes ('). This is shown in the following example: $util.escapeJavaScript(data).replaceAll("\\'","'")

关于json - AWS Lambda 错误 : 'Could not parse request body into json ' when url parameter contains JSON array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39291012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com