gpt4 book ai didi

javascript - ReactJS 获取 - 正文 : json. stringify

转载 作者:行者123 更新时间:2023-11-28 17:13:37 25 4
gpt4 key购买 nike

我的 Json 对象如下所示:

[
{
"keys": {
"_1": ".",
"_2": ".",
"_3": "."
},
"credits": -200,
"_id": "5c1e3e7531dccf0017cf70b9",
"firstName": "Martin",
"lastName": "Seubert",
"username": "admin",
"createdDate": "2018-12-22T13:39:01.244Z",
"__v": 0,
"id": "5c1e3e7531dccf0017cf70b9"
}
]

我想要以下函数将键设置为值,我从另一个 API 获取:

updateKeys() {
let user = JSON.parse(localStorage.getItem('user'));
var requestUrl = 'https://mighty-atoll-75521.herokuapp.com/users/';
var id = user._id
fetch(requestUrl + id, {
method: 'put',
headers: {
...authHeader(),
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({keys._1: this.props.code})
})
}

但是我在浏览器中收到此错误消息:

enter image description here

你对我有什么建议吗?

致以诚挚的问候

马丁

编辑:

在这里您可以找到完整的代码: https://github.com/kamami/prototype/blob/RealDatabase/src/components/ProgressMobileStepper.jsx

最佳答案

您正在尝试使用变量作为“属性”,因此您需要 ES6 中的CompulatedPropertyName。尝试用 body: JSON.stringify({[keys._1]: this.props.code})代替 body: JSON.stringify({keys._1: this.props.code})

关于javascript - ReactJS 获取 - 正文 : json. stringify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53946921/

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