I have a JSON array, and I want to pass it to drupal function to work with the data. what are the possible ways to do that?
any code sample would help
I have a JSON array, and I want to pass it to drupal function to work with the data. what are the possible ways to do that? any code sample would help |
||||
|
The function drupal_json_decode() (D7 only) can convert a json string to the corresponding php data structure. In Drupal 6, you can directly use the PHP function json_decode(), just remember that you need PHP 5.2+ for that. As I almost assumed, the part you're having problem with is not converting the JSON string to a PHP structure you can work with, but sending that from the client side to the server, so that you can access it with PHP (Try to provide more information what exactly you want to do when asking questions and you'll get better answers). drupal_json_decode() is, in fact, just the very last step in the whole process. You obviously can't access that function (or anything else that is PHP) directly from jQuery, so you need to send it with jQuery.post() to the server, where it can be processed. To be able to do that, you first need to define a endpoint where the data can be sent to by implementing hook_menu(), for example your_module/endpoint. In the page callback that you defined there, you can read the sent data in from php://input, for example with |
|||||||
|