title: convert JSON object to query string and then back to an object
body: <p>I know this has been asked a few times but please bear with me.</p>
  
  <p>I have a google maps object which is rather complex (it contains various nodes, coordinates, etc) and I am trying to pass it as a query string.</p>
  
  <p>I need a play javascript/jQuery solution.</p>
  
  <p>I have tried the .param method which gives a jQuery error. The only thing that works is the "stringify" method which then creates a string that when appearing as a url looks a bit like this: %7B%5C"shape_1%5C"%3A%7B%5C"color%5C"%3A%5C"%237F0000%5C"%2C%5C"data%5C"%3A%7B%5C"b%5C"%3A%5B%7B%5C"Na%5C"%3A51.56727431757122%2C%5C"Oa%5C"%3A-0.10462402858888709%7D%2C....</p>
  
  <p>php translates that as:
  {\\"shape_1\\":{\\"color\\":\\"#7F0000\\",\\"data\\":{\\"b\\":[{\\"Na\\":51.56727431757122,\\"Oa\\":-0.10462402858888709},...</p>
  
  <p>but having said that I don't want to use PHP, I am just showing you what it does in case it helps you see what stringify did to the object.</p>
  
  <p>After I unescape with Javascript it looks a bit more normal like:</p>
  
  <p>{\"shape_1\":{\"color\":\"#7F0000\",\"data\":{\"b\":[{\"Na\":51.56727431757122,\"Oa\":-0.10462402858888709},..</p>
  
  <p>So as you can see, the unescaped sequence has these slashes everywhere.
  When I try to evaluate that into a JSON object I get "Illegal token \". The parse method also fails. I just can't find any way to put this string back into the complex JSON object that it was.
  I have looked online for various suggestions but they fail. I also don't understand why stringify injects all these slashes which simply shouldn't be there.
  If anyone has an idea how to take that object, put it in a query string and then parse it back I would be very grateful.</p>
  
  <p>Nick</p>
  
  <hr>
  
  <p>Update:
  The answer is this:</p>
  
  <pre><code>encodeURIComponent(JSON.stringify(myObject));
  </code></pre>
  
  <p>And then on the receiving end: </p>
  
  <pre><code>var a = querySt("data");
  var b = decodeURIComponent(a);
  var c = unescape(b);
  var d = JSON.parse(c);
  </code></pre>
  
  <p>or all in one line </p>
  
  <pre><code>JSON.parse(unescape(decodeURIComponent(querySt("data"))));
  </code></pre>
  
  <p>Nick</p>