✅ – Liil' Boo – 08-41 Aug 10
Hey
Would something bad happen (or nothing), if I try to do
and 'thing' is not an object or array ?
Or does that change nothing ?
28 Replies
!title <JSON.parse question>
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
JSON.parse() - JavaScript | MDN
The JSON.parse() method parses a
JSON string, constructing the JavaScript value or object described by the string. An
optional reviver function can be provided to perform a transformation
on the resulting object before it is returned.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Could be anything else
What i'm really trying to is
And I want to be sure how to catch error
And if it always returns a string
Documentation didn't help me figure it out
Or I didn't understand
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Wait, what If I stringify everything before set to Local Storage ?
Then I would always deal with strings, right ?
As such
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
It's purely theoritical, I'm not coding
(Sorry I should have mentioned it)
Well, thank you for your time
I go with the approach of stringify-ing everything
either way localstorage can only store strings
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I guess so,
But documentation doesn't say what happens if I try
Would it become the string 'true' ? Or throw an Error
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
As a string ?
So localStorage can store booleans ? 😮
It'll stringify it yes
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Thanks for confirmation
As if you set
.setItem('... ', {});
it'll just stringify it into [object Object]
I'll stick to this approach, stringying everything, I'll think about accuracy* later
Thanks timo, thanks Eva
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I thought JSON.stringify would be harmless on things that are already a string
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
That's bad?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Well, better safe than sorry
I'll go with your advice, dear stranger
Thanks again
This question has an answer! Thank you for helping 😄
If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1006844848428568587
!close
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1006844848428568587