从HTTP解析器(AppSync)访问嵌套的属性

发布于 2025-01-26 10:37:53 字数 350 浏览 1 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星軌x 2025-02-02 10:37:53

我找到了一种以下方式提取解析的主体的方法:

#set ($parsed_body = $util.parseJson($ctx.result.body))

然后我能够通过点表示法访问属性:

parsed_body.about.firstName

我缺少的部分是$ util.parsejson(< json-string>)

看来身体是一个JSON字符串。

I found a way extract the parsed body in the following way:

#set ($parsed_body = $util.parseJson($ctx.result.body))

And then I am able to access the properties via dot notation:

parsed_body.about.firstName

The part I was missing is $util.parseJson(<json-string>)

It seems that the body is a JSON string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文