Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GuzzleHttp\Client JSON Return as String

Tags:

laravel

guzzle

I have very simple question, how to convert this strings to JSON ?

This string i am getting from Guzzle POST Request and here is code :

return $body->getBody()->getContents();

Result:

""k\n\n{\"success\":true,\"payload\":{\"id\":\"txn_ngS2aS9FY7raxy8JTUivAZCtWJy7EeznwPE8\"}}""

with var_dump result and what is that k before ?

string(79) "k {"success":true,"payload":{"id":"txn_eeM6T6Fvkq3Pr4AWtK2TKYmNwKmodNwVqJod"}}"
like image 539
Mandeep Gill Avatar asked Jul 30 '26 02:07

Mandeep Gill


1 Answers

The string is already json_encoded, you should simply return the $body->getBody()->getContents().

like image 199
Ozan Kurt Avatar answered Aug 01 '26 07:08

Ozan Kurt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!