Skip to content

Commit 2ca035d

Browse files
Update README.md
1 parent fcf4e99 commit 2ca035d

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,29 @@ $id = '1';
107107
$uri = 'https://example.com/_12345_/'.$resource.'/'.$id.'?key='.$key;
108108

109109
$client = new Guzzle();
110-
$response = $client->request('GET', $uri);
111-
$output = $response->getBody();
110+
$resp = $client->request('GET', $uri);
111+
$get_body = $resp->getBody();
112112

113113
// Чистим все что не нужно, иначе json_decode не сможет конвертировать json в массив
114-
for ($i = 0; $i <= 31; ++$i) {$output = str_replace(chr($i), "", $output);}
115-
$output = str_replace(chr(127), "", $output);
116-
if (0 === strpos(bin2hex($output), 'efbbbf')) {$output = substr($output, 3);}
117-
118-
$records = json_decode($output, true);
119-
120-
if (isset($records['headers']['code'])) {
121-
if ($records['headers']['code'] == '200') {
122-
$count = count($records['body']['items']);
123-
if ($count >= 1) {
124-
foreach($records['body']['items'] as $item)
125-
{
126-
print_r($item['item']);
127-
}
128-
}
129-
}
114+
for ($i = 0; $i <= 31; ++$i) {$get_body = str_replace(chr($i), "", $get_body);}
115+
$get_body = str_replace(chr(127), "", $get_body);
116+
if (0 === strpos(bin2hex($get_body), 'efbbbf')) {$get_body = substr($get_body, 3);}
117+
118+
$response = json_decode($get_body, true);
119+
120+
if (isset($response["headers"]["code"])) {
121+
if ($response["headers"]["code"] == 200) {
122+
$count = count($response["body"]["items"]);
123+
if ($count >= 1) {
124+
foreach($response["body"]["items"] as $item)
125+
{
126+
// Если $value object переводим в array
127+
$item = is_array($value["item"]) ? $item["item"] : (array)$value["item"];
128+
// Получаем данные
129+
print_r($item["name"]);
130+
}
131+
}
132+
}
130133
}
131134
```
132135

0 commit comments

Comments
 (0)