title: Convert string of PHP array to javascript Object
body: <p>I have a code that encodes a javascript object into something like this:</p>
  
  <pre><code>&lt;script&gt;
      var php_string='array("one"=&gt;"value_one","two"=&gt;"value_two")';
  &lt;/script&gt;
  </code></pre>
  
  <p>Now I would like to know how can I convert this into that:</p>
  
  <pre><code>{
      "one":"value_one",
      "two":"value_two"
  }
  </code></pre>
  
  <p>The content of <code>php_string</code> is sent to PHP on a <code>$_POST</code> variable. Is there anyway to do that or should I use JSON instead?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As asked, here is the code that made my <code>php_string</code>:</p>
  
  <pre><code>function encodeFormOptions(inputsWrapper){
      var the_serialize=$(inputsWrapper).find(":input").serializeArray();
      var text="array(";
      $.each( the_serialize, function( key, value ) {
          text+='"'+value["name"]+'"=&gt;'+'"'+value["value"]+'",';
      });
      if (text.charAt(text.length-1)==",")
          text=text.substring(0,text.length-1);
      text+=");";
      return text;
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I forgot to say that I need this conversion in pure Javascript. In other words, I need to parse the array string into a javascript Object because when a click on a certain button on my page occurs, I need to read the values that are currently inside <code>php_string</code>.</p>
  
  <p><strong>EDIT 3 (The full reason of the <code>php_string</code>)</strong> </p>
  
  <p>I tried to abstract the problem but, now I see that I shouldn't have done it.</p>
  
  <p>I have a page form that have some input's and multiple buttons named "options"</p>
  
  <p>When I click on any of these buttons, a popup appears with dynamic fields (derived from the option selected on a select field) on it and, when I fill all the input's, I create the <code>php_string</code> and save it on an hidden field.</p>
  
  <p>Now I want that when I click again on one of the "options" buttons, I could read what I saved on the hidden field, in order to put the default values that the popup input's should show if the selected option of the select field doesn't change.</p>
  
  <p>The hidden field is then parsed on PHP.</p>