Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read JSON data in Drupal 7

Tags:

drupal

I have a Server 1 which will post JSON data to my Server 2 URL (Drupal Site)

Sample JSON Request Object

{"ConfirmationNumber":"344", "E-mailAddress":"[email protected]", "FirstName":"FIRSTNAME", "LastName":"LASTNAME", "SKU":"XYZ"}

I need to read the above request in Drupal site means Server 2 to parse the JSON Object and to do some business logic. Any quick help is really appreciated

Example: http://mydrupalsite.com/services/register

Some external site is posting the JSON data to my above URL.

I need to read the JSON Content they posted in my drupal site. This is what I want. Getting/Reading the data is the my first step. Parsing is fine which we can do as next step.

like image 589
Kalyan Raju Avatar asked Feb 14 '23 15:02

Kalyan Raju


1 Answers

To read json response.

$url = "your request url";
$request = drupal_http_request($url);
$json_response = drupal_json_decode($request->data);
foreach ($json_response as $response_data) {
  //your operation code  
}
like image 53
smsivaprakaash Avatar answered Mar 08 '23 12:03

smsivaprakaash