1
I have a Json object coming from localStorage and I need it to be converted to a Long type, in case entidadeId
idEntidade = localStorage.getItem("idEntidade");
var entidadeId = JSON.parse(idEntidade);
1
I have a Json object coming from localStorage and I need it to be converted to a Long type, in case entidadeId
idEntidade = localStorage.getItem("idEntidade");
var entidadeId = JSON.parse(idEntidade);
4
Since Javascript is not a strongly typed language, I suggest you just convert your variable to a number, as follows:
idEntidade = Number(localStorage.getItem("idEntidade"));
Browser other questions tagged javascript json localstorage
You are not signed in. Login or sign up in order to post.
" be converted to a Long" - what is a "Long"?
– Sergio
long type, such as int
– Eduardo Krakhecke
That’s not
Java
?– Sam
I’m doing it by Avascript
– Eduardo Krakhecke
I don’t know this guy Long.
– Sam
@Eduardokrakhecke ok. No Javascript available Long. This string you want to convert has text or only numbers?
– Sergio
@Sergio has only one number
– Eduardo Krakhecke
So Breno’s answer does what you need.
– Sergio
Even though Long does not exist, I was curious to know what would be the purpose in converting? I would be very grateful to know :)
– Sam
@DVD is because the
localStorage
keeps everything in String.– Sergio
@Sergio Verdade. Thanks!
– Sam
@DVD is that I am saving a parameter that is an id in localStorage, and at that moment I need to pass it in a request,and the request asks for a Long type, but it is a String in localStorage, so I needed to convert.
– Eduardo Krakhecke
I get it. But this Long you got from where, from Java?
– Sam
@DVD yes, it’s coming from Java.
– Eduardo Krakhecke