title: confused over proper way to use json
body: <p>I'm new to jquery and just started reading up on json early last night.  <strong>I have a working ajax call that passes simple data to a php script, works on the data and returns a single value.</strong> Works great.</p>
  
  <p><strong>I want to add the passing of arrays and non array data back and forth</strong> and after reading piles of articles saying json IS the way to go!!!!  BUT... also that json isn't secure, ... put braces, dont put braces - use json decode, dont use it, make sure the top item is an object, some say put a "d" at the top, some use serialization, some don't use it.  Do I have to put the curley braces around the data?  Or does Jquery.  Some people have said to also add a header that specifies application/json or some other header... and others have said it breaks IE7...  some have said to add ...</p>
  
  <p><code>"dataType" : json</code></p>
  
  <p>in the ajax call.  Do you see why I am confused now?</p>
  
  <p>... and ... In the PHP do I have to also use rawurldecode? before json decode since my ajax urlencodes the data ...  it's sooo confusing...</p>
  
  <p>I don't want this to be a bigger security hole than it already is... I would like to do it PROPERLY and to SPEC. if there is a spec.</p>
  
  <p>Most people thankfully say... it's about HOW you use it (jquery, JSON) etc and THAT makes it "secure".  And by secure... I mean, used properly.  Nothing on the client side is EVER secure.</p>
  
  <p>What I'm stuck on is simple I'm sure but after reading for over 9+ hours I can't find a definitive answer.  Why can't the people who make the languages (Jquery) write an example that says... here's the PROPER way to do it now that we have included json support!?!</p>
  
  <p>And yes, I'm being a tad wordy in this top portion because I've asked short questions before and been downvoted and criticized and accused of not researching things or not "looking into it enough" when I NEVER ask a question here without at least 5+ hours of intense reading, scanning websites, etc.. and usually I only come here after way over 9+ hours ... </p>
  
  <p>...but the information I have found is broken, old, and in too many pieces and I want to do it PERFECTLY!!! :)  The best website I found so far was for pulling in flicker pictures but it didn't show how to send properly so I left there happy to find the article... but didn't know how to apply it to MY situation...</p>
  
  <p><em>Please see the comments in my code for the tips I need please or even better - fix up my code so I can send those 2 datas back and forth and in each language can you assign a value to a tmp variable so I can SEE how you extract the information from the passed data?  Thanks...</em></p>
  
  <p>JQUERY/JS (my old code) (code snippits)</p>
  
  <pre><code>    //Here's some sample data... - HOW DO I SEND THIS AS JSON (please) back and forth?
      var myarray = new Array();
      myarray.push("One");
      myarray.push("Two");
      myarray.push("Three");
      var someOtherData = "helpmeplease";
  
      $.ajax({
          url: "../../ajax/ajax.php",
          type: 'POST',
          data: ({
              "testarray" : myarray,
              "somemoredata" : someOtherData
          }),
          success: function(results) {
              // what do I do with results?  please alert the 2 passed variables back from php
              // for example alert("Test:" . results[0] . results.someOtherData) or however you
              // access the returned values...
  </code></pre>
  
  <p>PHP RECEIVE FROM AJAX (my old test code)</p>
  
  <pre><code>     $test1 = rawurldecode($_POST["somemoredata"]);
       $test2 = rawurldecode($_POST["testarray"]);
       $test3 = testarray[0]; // should be One
  </code></pre>
  
  <p>PHP RETURN</p>
  
  <pre><code>     // please send any data back to the Ajax call 1 array, 1 normal data please and alert
       // the data please so I can see how it's pulled back out...
       return $data; // 1 array, 1 normal variable please
  </code></pre>
  
  <p>More info on my stuff...</p>
  
  <ul>
  <li><p>my website is UTF-8 encoded</p></li>
  <li><p>My data set will be under 4 megs.  Most likely under 200k.</p></li>
  <li><p>No cross domain stuff taking place</p></li>
  <li><p>I have a nonce, per page token authentication system that works great</p></li>
  <li><p>what can go in the data?  ANYTHING?  Any symbols, or stuff that should NOT be included that would break the JSON code or the passing of data back and forth?</p></li>
  <li><p>any other tips, suggestions, warnings?</p></li>
  </ul>
  
  <p>Thank you for your time.</p>