首页 文章

将JSON对象附加到URL的末尾

提问于
浏览
2

我有这段代码:

//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'];

但由于某种原因,我无法将ID附加到URL的末尾 . 有任何想法吗?

2 回答

  • 3

    这是因为json decode不会给你一个数组,而是一个对象 . 代替:

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

    您的代码失败的原因是因为您尝试使用对象就像它是一个数组一样 . 将最后一行替换为:

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

相关问题