Ich habe versucht, einen ReactJS Abruf an eine REST-API abrufen und die Antwort behandeln möchten. Der Aufruf funktioniert, ich eine Antwort erhalten, die ich in Chrome Dev-Tool sehen:Handle Response - SyntaxError: Unerwartetes Ende der Eingabe
function getAllCourses() {
fetch('http://localhost:8080/course', {
method: 'POST',
mode: 'no-cors',
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
objectClass: 'course',
crud: '2'
})
}).then(function (response) {
console.log(response);
return response.json();
}).catch(function (err) {
console.log(err)
});
}
Wenn ich versuche, die Antwort zu handhaben, ich habe einen „Syntaxerror: unerwartetes Ende der Eingabe“ bei
return response.json();
Die console.log sieht wie folgt aus:
JSON Meine Antwort wie folgt aussieht, ist es gültig, ich habe es mit jsonlint:
[
{
"0x1": {
"users": [],
"lectures": [],
"owner": "0x2",
"title": "WWI 14 SEA",
"description": null,
"objectClass": "course",
"id": "course_00001"
},
"0x2": {
"username": "system",
"lectures": [],
"course": null,
"solutions": [],
"exercises": [],
"roles": [
"0x3",
"0x4",
"0x5"
],
"objectClass": "user",
"id": "user_00001"
},
"0x3": {
"roleName": "ROLE_ADMIN",
"objectClass": "role",
"id": "role_00001"
},
"0x4": {
"roleName": "ROLE_STUDENT",
"objectClass": "role",
"id": "role_00002"
},
"0x5": {
"roleName": "ROLE_DOCENT",
"objectClass": "role",
"id": "role_00003"
}
}
]
können Sie 'console.log (response)' vor 'return response.json()' verwenden und das Ergebnis anzeigen? –
Ich habe es zur Frage hinzugefügt – Chilliggo