狂饮6:没有更多的json()方法来响应 [英] Guzzle 6: no more json() method for responses
问题描述
以前在Guzzle 5.3中:
Previously in Guzzle 5.3:
$response = $client->get('http://httpbin.org/get');
$array = $response->json(); // Yoohoo
var_dump($array[0]['origin']);
我可以轻松地从JSON响应中获取一个PHP数组.现在在《食尸鬼6》中,我不知道该怎么办.似乎不再有json()
方法.我(快速)从最新版本中阅读了该文档,但未发现有关JSON响应的任何信息.我想我错过了一些东西,也许有一个我不理解的新概念(或者我没有正确阅读).
I could easily get a PHP array from a JSON response. Now In Guzzle 6, I don't know how to do. There seems to be no json()
method anymore. I (quickly) read the doc from the latest version and don't found anything about JSON responses. I think I missed something, maybe there is a new concept that I don't understand (or maybe I did not read correctly).
这是(下面)新方法唯一的方法吗?
Is this (below) new way the only way?
$response = $client->get('http://httpbin.org/get');
$array = json_decode($response->getBody()->getContents(), true); // :'(
var_dump($array[0]['origin']);
或者有帮助者之类的东西吗?
Or is there an helper or something like that?
推荐答案
我现在使用json_decode($response->getBody())
而不是$response->json()
.
我怀疑这可能是PSR-7遵从性的牺牲品.
I suspect this might be a casualty of PSR-7 compliance.
这篇关于狂饮6:没有更多的json()方法来响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!