我想盡我所能解釋這一點,請問我對某事不太清楚。 我正在使用一個API,在那裏我得到一堆關於傳感器的信息。從JSON_DECODE獲取一定的信息
這是一類
public function getSensors()
{
$params = array();
return json_decode($this->consumer->sendRequest(constant('REQUEST_URI').'/sensors/list', $params, 'GET')->getBody());
在我的index.php
$params = array('id'=> XXXXXX);
$response = $consumer->sendRequest(constant('REQUEST_URI').'/sensor/info', $params,'GET');
echo json_decode($response->getBody());
這給我的信息,這樣的塊的方法:
{"id":"xxxxx","client":"xxxx","name":"xxxxx","lastUpdated": xxxx}
我只想用一些該信息。
這是getBody()如果您使用的是API,你無法控制你所得到的信息,除非API定義這樣做的方法方法 -
public function getBody() {
if (self::METHOD_POST == $this->method && (!empty($this->postParams) || !empty($this->uploads))) {
if (0 === strpos($this->headers['content-type'], 'application/x-www-form-urlencoded')) {
$body = http_build_query($this->postParams, '', '&');
if (!$this->getConfig('use_brackets')) {
$body = preg_replace('/%5B\d+%5D=/', '=', $body);
}
// support RFC 3986 by not encoding '~' symbol (request #15368)
return str_replace('%7E', '~', $body);
} elseif (0 === strpos($this->headers['content-type'], 'multipart/form-data')) {
require_once 'HTTP/Request2/MultipartBody.php';
return new HTTP_Request2_MultipartBody(
$this->postParams, $this->uploads, $this->getConfig('use_brackets')
);
}
}
return $this->body;
}
'所以我可以修改它與CSS'你是什麼意思的 – meda
回聲json_decode()應該無法工作,如果響應正文是一個正確的JSON對象,你會試圖回聲一個PHP目的。 JSON_Decode對JSON字符串進行解碼並返回一個PHP對象,然後您可以對其進行操作以選擇性地輸出或輸出爲HTML。亞歷山大 - –
- 感謝您的迴應。我不確定我是否遵守。最後一部分是PHP對象嗎?如果是這樣,我怎麼操縱它?謝謝。 – Trollgubbe