The 6 version introduced the use of this line; line 21 within json_server_server.
$request = drupal_parse_json($_POST['method']);
within drupal_parse_json if json_decode exists it will do the work and return an object. However if it doesn't exist it returns an array. I'm probably tired but I'm confused as to why this is. Moreover the check just a few lines down in.
$method['#method'] == $request
which is essentially a string comparison against an object (return from json_decode) or an array. Both of which fail.
I'm sure I'm missing something here.. what is it?
Comments
Comment #1
andremolnar commentedI haven't actually been using the 6.x version and just looking at the code has me scratching my head as to why there would be json parsing at all on the server side.
For now, filing under things that make me go hmmmm.... Will try and release an official 6.x version soon.
Comment #2
skyredwangwith some digging, json_decode requires (PHP 5 >= 5.2.0, PECL json >= 1.2.0) http://php.net/manual/en/function.json-decode.php;
I actually experienced the same issue on some shared hosting. it seems that drupal_parse_json current fall back plan does not work.
Comment #3
Bobby.Cottle commentedPerhaps I am missing something obvious here, but I have seen a number of comments about removing Drupal's ability to decode JSON data. This attitude is very puzzling to me.
Of course it makes sense to allow the server to handle JSON data!
Data sources are not always meant to be accessible to the end user, and thus his browser. This is how DBMS backends work, for example. The user knows nothing about the source of the data, only the data itself.
And if the server wishes to take action based on that data, then it needs to process it before returning anything to the user. When data is sent as JSON, what will the server do if you have removed this functionality from Drupal?
We cannot assume JSON will only ever be used for public data sources, so the capability must always be there for the server side to decode it.
Thus, please fix this bug rather than remove Drupal's JSON ability.
Comment #4
AndyThornton commentedI didnt want to create a new 'issue' but i thought i would just mention something. it is somewhat related to this task, in that it is pertaining to parsing the JSON string. It is in the JS, though. Just incase anyone stumbles over this the json_server module doesnt appear to be compatible with devel (at least certain configurations of it). If you leave the devel setting on where it prints the time it took to build the page that ends up being present at the end of the response back and the json_server fails silently. the RPC is called and a response is received, but when it calls Drupal.parseJson things go wrong.
obviously, this isnt the biggest of deals - but i thought i'd mention it as maybe a few folks run devel on in their dev environments.
cheers!
Comment #5
skyredwangComment #6
Nick Robillard commentedThis happened twice for me. Both times, it was because json_decode() required valid json. Because $_POST['method'] will never actually be json, it returned empty. Fyi, the PHP version where json_decode() returned empty is 5.2.17. PHP 5.2.4 returned the non-json string as expected.
I fixed this in my patch here - http://drupal.org/node/443090#comment-3476556.