从HTTP解析器(AppSync)访问嵌套的属性
我是AWS Appsync的新手,我正在尝试在解析器的响应映射模板中访问某些身体属性(从HTTP响应)。 例如:我能够通过$ util.tojson($ ctx.result.body)
来表达响应,但是当我尝试获得一些嵌套的身体属性时,它会失败。
例如,想象一下身体看起来像这样:
{
about:{
"firstName":"Chuck",
"lastName":"Norris"
}
}
$ util.tojson($ ctx.result.body.about)
返回null
。有什么想法吗?
I'm new to AWS AppSync and I am trying to access certain body property(from HTTP response) in my resolver's response mapping template.
For example: I am able to present the response as is via $util.toJson($ctx.result.body)
, but when I try to get some of the nested body properties it fails.
For example, imagine the body looks like this:
{
about:{
"firstName":"Chuck",
"lastName":"Norris"
}
}
and $util.toJson($ctx.result.body.about)
returns null
. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种以下方式提取解析的主体的方法:
然后我能够通过点表示法访问属性:
我缺少的部分是
$ util.parsejson(< json-string>)
看来身体是一个JSON字符串。
I found a way extract the parsed body in the following way:
And then I am able to access the properties via dot notation:
The part I was missing is
$util.parseJson(<json-string>)
It seems that the body is a JSON string.