How do I access this JSON Element? (PHP) -


what doing wrong? code:

$json_url = "https://futservices.com/futfillorder/futfillwebservice.asmx/new"; $apikey = "..........";  $data_json = '{"user":"...........", "customer" {"username":".....","password":".....","phishing":"....."},"seller":{"username":".....","password":"......","phishing":"....."},"amount":10000,"platform":"ps"}';       $ch = curl_init($json_url);      curl_setopt_array($ch, array(     curlopt_post => true,     curlopt_postfields => $data_json,     curlopt_header => true,     curlopt_httpheader => array(               'connection: keep-alive',               'accept: application/json',               'content-type: application/json; charset=utf-8',               'host: futservices.com',               'content-length: '.strlen($data_json).'',               'accept-encoding: gzip'               ))    );       $response  = curl_exec($ch);     curl_close($ch);      echo $response;      $order = json_decode($response, true);       echo "your token is: ".$order['d'];` 

the request goes through fine, however, want grab "d" json element sent in json response api.

this response:

http/1.1 200 ok cache-control: private, max-age=0 content-length: 44 content-type: application/json; charset=utf-8 server: microsoft-iis/8.5 x-aspnet-version: 4.0.30319 x-powered-by: asp.net date: sat, 25 apr 2015 16:58:09 gmt {"d":"d922bad4-60d8-4fe4-9cba-0231328744a0"}1your token is: 

as can see "d" not echoed after "your token is: ". how can resolve this?

you need set curlopt_return_transfer flag store result of curl variable. what's happening response being sent straight browser. add option have done below.

 curl_setopt_array($ch, array(     curlopt_post => true,     curlopt_postfields => $data_json,     curlopt_header => true,     curlopt_return_transfer => true,     curlopt_httpheader => array(               'connection: keep-alive',               'accept: application/json',               'content-type: application/json; charset=utf-8',               'host: futservices.com',               'content-length: '.strlen($data_json).'',               'accept-encoding: gzip'               ))    ); 

i hope helps!


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -