> > From: Mark > > $event = json_encode($super_array); > From: Stephan Beal > How about simply: > $event = '['.$event.']';
If $event contains the JSON encoded object from the previous message, then this code would not convert that object into a JSON array. It would simply create an array of one element, where that element is the original object. Probably not what Mark wants. Mark, PHP uses a single Array type for both numerically-indexed arrays (like an Array in JavaScript) *and* for associative arrays (like an Object in JavaScript). So the json_encode function inspects the array to see whether it has only numeric indexes or has other properties as well, and then it generates either a JSON array or object depending. If you want a JSON array to be output, make sure your PHP array is a simple array, e.g.: array( 'x', 'y', 'z' ) and *not* an associative array, e.g: array( 'a' => 'x', 'b' => 'y', 'c' => 'z' ) > on the server side, i personally recommend using the json2.js > API (i.e. JSON.parse() and JSON.stringify()) over > $.getJSON(). getJSON uses an HTTP GET, which is very rude > vis-a-vis Apache logs (because all your JSON gets logged > there in urlencoded form). No, that's wrong. Yes, $.getJSON() does do a GET, but that has no effect at all on the *download* format, which is what Mark is asking about given his use of json_encode. Your downloaded JSON data will not show up in any Apache logs (unless, I suppose, if you have some kind of ultra-verbose logging turned on that logs the entire content of all HTTP responses). The Apache logs will include all the query parameters sent up with an HTTP *request*, but not all the content of each response. So if you are *uploading* JSON data to your server, yes, it's a good idea to use JSON.stringify() and put it in a POST. If you are merely querying the server with ordinary (typically fairly small) query parameters, then using a GET will not clutter your logs. Also, how would you use json2.js on your server? Mark's server is running PHP, not JavaScript. json2.js is JavaScript code to run in the browser. -Mike