title: Double encode for JSON
body: <p>In most of my AJAX functions I have to double encode free text entered by a user, i.e. I have to do encodeURIComponent(encodeURIComponent(myString)).</p>
  
  <p>If I do it just once most symbols except double quotes and long hyphens work.</p>
  
  <p>If I alert out the result from a single encode quotes are encoded, but it breaks the JSON string which is why I am confused.</p>
  
  <p>Is this a bug with JavaScript or am I missing something? Is it related to the way that you have to double encode ampersand in PHP to get it to work?</p>
  
  <hr>
  
  <p>Hi,</p>
  
  <p>Here is the code that lets a user store a note against something:</p>
  
  <pre><code>function saveAdminNote() {
  
  var note = encodeURIComponent(encodeURIComponent($('#adminNote').val().replace(/(\r\n|\n|\r)/gm,""))) ;
  JSON = '{"mode":"UPDATE_INTNOTE", "jobid":'+jobId+', "note":"'+note+'"}' ;
  
  clearTimeout(tOut2) ;
  tOut2 = setTimeout(function(){             
      $.ajax({
          data: 'dataString='+JSON,
          url: 'core/job-builder-controlV2.php',
          type: 'POST',
          success: function(data){
              if(data)
              {
                  $.prompt(data) ;
              }
          }
      })
  
  }, 250) ;
  
  }
  </code></pre>
  
  <hr>
  
  <p>So if my data structure is flat, there is no advantage to using JSON at all?</p>
  
  <p>I was under the impression that JSON gave a little more security?</p>