Mistake:

Warning: json_decode () expects parameter 1 to be string

Code:

$res = json_decode($curl->post('https://auth.qiwi.com/cas/tgts', json_encode(array( 'login' => '+79999999999', 'password' => '123123' )))); $TgtTicket = $res->entity->ticket; echo $TgtTicket; 

Which essentially returns $ curl-> post ...:

 stdClass Object ( [entity] => stdClass Object ( [user] => +79139962423 [ticket] => TGT-391357-QO7amrRgf2kOPxhhxWdo9FZUrdIZhJLCIOQHbk6jMEjfLuSePg ) [links] => Array ( [0] => stdClass Object ( [rel] => sts [href] => https://auth.qiwi.com/cas/sts ) ) ) 

But json_decode cannot somehow decode it, although everything seems to be correct.

  • $curl - what is this object? What library / CMF do you use? - tutankhamun
  • You yourself wrote that $curl->post() gives you a stdClass Object . And json_decode() expects an input string. - koks_rs
  • Pretty damn cute. Thanks for the tip - tutankhamun

1 answer 1

Not. Not true json_decode decodes only the string, and you transfer the finished object. Something seems to me that your $curl->post() independently decoded everything and you don’t need to do anything else.

Updated

Looked source. Curl::post() automatically parses JSON and XML if the Content-Type response header is accordingly similar to JSON or XML (for example, application / json or text / xml)

  • That's right, thanks! - Rufex