Convert Json to Long type

Asked

Viewed 70 times

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);
  • " be converted to a Long" - what is a "Long"?

  • long type, such as int

  • That’s not Java?

  • I’m doing it by Avascript

  • I don’t know this guy Long.

  • @Eduardokrakhecke ok. No Javascript available Long. This string you want to convert has text or only numbers?

  • @Sergio has only one number

  • So Breno’s answer does what you need.

  • 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 :)

  • @DVD is because the localStorage keeps everything in String.

  • 1

    @Sergio Verdade. Thanks!

  • @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.

  • I get it. But this Long you got from where, from Java?

  • @DVD yes, it’s coming from Java.

Show 9 more comments

1 answer

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

You are not signed in. Login or sign up in order to post.