1

下面是我的代码,我试图在 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 ) )
4

1 回答 1

1

你不需要json_decode这个。它已经是一个 php 对象。

$response->body->Operator应该给你你正在寻找的结果。

于 2015-02-19T14:13:30.207 回答