3

I am trying to encode and decode an object from a url. The structure of the object looks like so

 myObj =
 {"obj1": {"sub1" : 1, "sub2", "2"},
  "obj2": {"sub1" : 1, "sub2", "2"},
  "obj3": {"sub1" : 1, "sub2", "2"} }

And So what I'm trying to do is encode it and decode it from the url - for reference this is for saving a "state". So it encode it, I have

 encodeURIComponent(JSON.stringify(data));

And to decode I have :

JSON.parse(decodeURIComponent(searchString));

Then using Angualrs,

 $location.search();

to set and pull the url.

This was working fine until I changed the values inside the object to objects them selves, the URL just says "object", and I can't pull any data from it. Could use some help. The basic Idea is - i just want to be able to save and pull this object from the url. Thanks!

Update :

it seems when I encode a new object I get a result like this

   {{"obj1":{"sub1":true}}: true}

so it's acting very oddly with the object

Edit:

Upon further research it appears what I'm looking for is something like jquery's param (and deparam), but in just javascript?

ajmajmajma
  • 13,712
  • 24
  • 79
  • 133

0 Answers0