使用axio的数据,其名称包含括号

发布于 2025-01-28 06:55:02 字数 423 浏览 1 评论 0原文

我目前在Axios请求中遇到问题。

这是我查询结果的一个示例:

{
"results": [
{
"first_result": "123",
"second_result(abc)": "456"
}
]
}

如您所见,第二行包含括号。 如何使用我的Usestate获取此数据(在这里“ 456”)?

 axios
      .get(API)
      .then((response) => response.data)
      .then((data) => {
       setObject(data.results[0].second_result(abc)))
        
        
      })

非常感谢您,祝您有美好的一天! =)

I am currently experiencing a problem with my axios request.

Here is an example of the result of my query:

{
"results": [
{
"first_result": "123",
"second_result(abc)": "456"
}
]
}

As you can see, the second line contains parentheses.
How can I get this data (here "456"), with my useState?

 axios
      .get(API)
      .then((response) => response.data)
      .then((data) => {
       setObject(data.results[0].second_result(abc)))
        
        
      })

Thank you very much and have an nice day ! =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

意中人 2025-02-04 06:55:02

像这样:

data.results [0] ['second_result(abc)']

Like this:

data.results[0]['second_result(abc)']

小草泠泠 2025-02-04 06:55:02

您需要使用括号符号访问second_result(abc),因为属性名称不是有效的JavaScript标识符。像A. results [0] ['second_result(abc)']

You will need to access second_result(abc) using bracket notation because property name is not an valid javascript identifier. like a.results[0]['second_result(abc)']

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