使用axio的数据,其名称包含括号
我目前在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:
data.results [0] ['second_result(abc)']
Like this:
data.results[0]['second_result(abc)']
您需要使用括号符号访问
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. likea.results[0]['second_result(abc)']