rabid_zombie
rabid_zombie

Reputation: 992

Appending JSON object to the end of URL

I have this bit of code:

       //execute post (the result will be something like {"result":1,"error":"","id":"4da77536a2338","lockcode":"4af15b3725eb5cf3641d96f6c7a3b71d"})
       $result = curl_exec($ch);
       $response = json_decode($result);

       //close connection   
       curl_close($ch);

       $imageHref = 'http://my.site.com/render?id=' . $response['id'];

But I can't append the id to the end of the URL for some reason. Any ideas?

Upvotes: 2

Views: 1331

Answers (2)

Mala
Mala

Reputation: 14853

The reason your code is failing is because you're trying to use an object as though it were an array. Replace your last line with:

$imageHref = 'http://my.site.com/render?id=' . $response->id;

Upvotes: 3

Jage
Jage

Reputation: 8096

It's becase json decode does not give you back an array, but instead an object. Instead:

$imageHref = 'http://my.site.com/render?id=' . $response->id;

Upvotes: 5

Related Questions