98
rated 0 times
[
104]
[
6]
/ answers: 1 / hits: 14836
/ 5 Years ago, fri, may 31, 2019, 12:00:00
I'm trying to send an array using fetch that looks like this:
{cards:[[189,2],[211,2],[238,2],[778,2],[985,2],[1008,2],[1073,2],[1171,2],[48886,2],[49161,2],[49164,2],[49184,1],[49356,2],[50372,2],[51722,1],[52422,2]],heroes:[1066],format:2}
Here is what I am trying:
getCardsForDeck = deck => {
var stringifiedDeck = JSON.stringify(deck);
console.log(stringifiedDeck: + stringifiedDeck);
fetch(`http://localhost:3001/api/getCardsForDeck`, {
method: PUT,
body: stringifiedDeck
})
.then(cards => cards.json())
.then(res => this.setState({ cards: res.cards }));
};
I am getting an error though:
Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0
How do I send this data if not with JSON.stringify() or do I have to edit the data to remove the brackets?
Upon checking the api in the network tab it gives me this:
SyntaxError: Unexpected token o in JSON at position 1
[0] at JSON.parse (<anonymous>)
[0] at parse (C:UsersUserprojectswebappdeck-editorbackendnode_modulesbody-parserlibtypesjson.js:89:19)
[0] at C:UsersUserprojectswebappdeck-editorbackendnode_modulesbody-parserlibread.js:121:18
[0] at invokeCallback (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:224:16)
[0] at done (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:213:7)
[0] at IncomingMessage.onEnd (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:273:7)
[0] at IncomingMessage.emit (events.js:194:15)
[0] at endReadableNT (_stream_readable.js:1125:12)
[0] at process._tickCallback (internal/process/next_tick.js:63:19)
[0] SyntaxError: Unexpected token o in JSON at position 1
[0] at JSON.parse (<anonymous>)
[0] at parse (C:UsersUserprojectswebappdeck-editorbackendnode_modulesbody-parserlibtypesjson.js:89:19)
[0] at C:UsersUserprojectswebappdeck-editorbackendnode_modulesbody-parserlibread.js:121:18
[0] at invokeCallback (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:224:16)
[0] at done (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:213:7)
[0] at IncomingMessage.onEnd (C:UsersUserprojectswebappdeck-editorbackendnode_modulesraw-bodyindex.js:273:7)
[0] at IncomingMessage.emit (events.js:194:15)
[0] at endReadableNT (_stream_readable.js:1125:12)
[0] at process._tickCallback (internal/process/next_tick.js:63:19)
More From » node.js