【发布时间】:2015-02-19 13:46:21
【问题描述】:
以下是我的代码,我正在尝试在 php 字符串中获取特定的 mashape api 响应(运算符)。
require_once 'vendor/autoload.php';
$response = Unirest\Request::get("https://sphirelabs-mobile-number-portability-india-operator-v1.p.mashape.com/index.php?number=8055144322",
array(
"X-Mashape-Key" => "XXXXXXXXX",
"Accept" => "application/json"
)
);
json_decode($response, true);
echo $response['operator'];
回复:
Unirest\Response Object (
[code] => 200
[raw_body] => {"Telecom circle":"Maharashtra","Operator":"Reliance GSM","Is MNP":"False"}
[body] => stdClass Object (
[Telecom circle] => Maharashtra
[Operator] => Reliance GSM
[Is MNP] => False
)
[headers] => Array ( [0] => HTTP/1.1 200 OK [Accept-Ranges] => none [Content-Encoding] => gzip [Content-Type] => application/json [Date] => Thu, 19 Feb 2015 14:04:39 GMT [Server] => Mashape/5.0.6 [Vary] => Accept-Encoding [Content-Length] => 91 [Connection] => keep-alive ) )
【问题讨论】:
-
听起来你得到的结果不是 json。发布
print_r($response)的结果,以便我们了解您在处理什么。 -
我已经尝试了 print_r($response) 并且我在 json 中正确获取了所有 api 响应,但我想要来自 api 的特定响应(运算符)。
-
你问题中的错误告诉我
$responseis not json. -
我编辑了我的代码。现在,请解决问题。