0

I am getting this response in magento 2 curl. Do you know, how we can convert this response into array?

Here is my code:

$this->curlClient->post($url, $post);
$responseCurl = $this->curlClient->getBody();
print_r($responseCurl);

Current O/P:

{"status":true,"data":{"name":null,"start":"2018-04-19 11:07:02","end":"2018-04-19 11:07:02","discount_type":"P","discount_amount":12,"code":"abc_123"}}

Thanks in advance?

0

Try json_decode:

 $this->curlClient->post($url, $post);
$responseCurl = $this->curlClient->getBody();
$data = json_decode($responseCurl, TRUE);
print_r($data);

The second parameter will make json string into an associative arrays.

  • its not working in magento 2.1.3 – Pankaj Sharma Apr 27 '18 at 6:37
  • It's PHP standard code it should work , I have tested it on my pc and working fine with your json data – Arunendra Apr 27 '18 at 6:45
  • Yes but its not working with magento CURL – Pankaj Sharma Apr 27 '18 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.