Parsing a fetch response resulting number turning into NaN
Hi there! I'm making a website where I try to gameify the experience. However now im stuck with a problem! So I fetch energy from my supabase table. So far so good. but when I parse the response one field ("balance") gets turned into NaN!
I have no idea how to resolve the issue here!
Thanks for the help in advance ❤️
11 Replies
That does appear to be odd
So im not crazy:P
I feel like im going insane!
My only guess would be that it's not actually a 5 but some other character that looks like a 5
Or maybe there is an invisible character next to it screwing up the parsing
It is a 8 byte int so im pretty certain its a 5:)
i might be a little obtuse but have you tried just directly using await response.json()
MDN Web Docs
Response: json() method - Web APIs | MDN
The json() method of the Response interface takes
a Response stream and reads it to completion. It returns a promise which
resolves with the result of parsing the body text as JSON.
other than that maybe the json parser has a bug in it
or do you change the data object after because the console updates it @wedmaniac
Hi, thx for the reply ! Yes. I have tried that!;)
No sir!
I was really baffled so I had to change direction! Now I include the data in the context!
Hmm... I'd still log data.userCurrency.balance just to narrow things down
Maby I encounter it in the future:)