【发布时间】:2021-06-14 10:31:21
【问题描述】:
{"user" : $payload.user,"Class" : "Division-II","Branch" : "div_branch-1"}
我有上面的 json 数据,当我试图通过 GET 请求访问它并显示在 HTML 页面上时,我能够在使用 respone => response.text() 时显示,但我得到了意想不到的令牌 $ 在10 当我使用response => response.json().
fetch('http://localhost:3000/features,{
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).then(response => response.json())
.then(data => {
var user = data[user];
})
如何解决这个问题。
【问题讨论】:
-
收到的 JSON 无效。您是如何创建数据的?
-
'Content-Type': 'application/json'是一个谎言。您根本没有将 JSON 发布到服务器。 -
“我有上面的 json 数据”——正如错误消息所说,这不是有效的 JSON。你需要解决这个问题。
-
其实是已有数据。
-
@HarshatejM — 预先存在与否,它仍然不是 JSON
标签: javascript json get