vendredi 29 septembre 2017

PHP Access JSON object inside api response

I am asking for and receiving a response to an Http call to a cloud document storage service (ShareFile): the full response is below.

HTTP/1.1 100 Continue HTTP/1.1 200 OK Cache-Control: private Content-Length: 313 Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 Access-Control-Allow-Origin: * Access-Control-Max-Age: 3628800 Access-Control-Allow-Headers: content-type Access-Control-Allow-Methods: OPTIONS, TRACE, GET, HEAD, POST Date: Fri, 29 Sep 2017 20:42:28 GMT X-SF-Server: storageCenter_HTTP/i-0d49984868dfc0715_172.16.100.22_us-east-1b Strict-Transport-Security: max-age=16000000; includeSubDomains; preload; {"error":false,"value":[{"uploadid":"6dba8852-b99a-4c2a-bc31-87d3ae26e3b0","parentid":"fo9b28ee-49fd-4812-9cdb-3d461e88a55a","id":"fif90a81-6c28-68f2-95ac-36a2e8d34639","filename":"TinManWoodProducts-bid75.pdf","displayname":"TinManWoodProducts-bid75.pdf","size":579398,"md5":"aee1fa760cf230340652b2ee130133ba"}]}

As you can see there is a json object nestled in there and I cannot figure out how to burrow in and retreive the json object. What I am particularly looking for is the "id":"fif90a81-6c28-68f2-95ac-36a2e8d34639".

I have tried json_decode($upload_response, true) which returns a null object, I have used utf8_encode (which makes no difference at all) and I have tried Laravel's ->json() (error - call to member function json() on string), and several other solutions to almost similar issues posted on stack overflow, but I still have no idea how to dig in and get the "id".

Php v:7.0.22 Laravel v:5.4

Any help greatly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire