将mashape api响应转换为php字符串 [英] converting mashape api response to php string

查看:94
本文介绍了将mashape api响应转换为php字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,我试图在php字符串中获得特定的mashape api响应(运算符).

Below is my code, I am trying to get particular mashape api response (operator) in php string.

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_decode.它已经是一个php对象.

You don't need to json_decode this. It's already a php Object.

$response->body->Operator应该会为您提供所需的结果.

$response->body->Operator should give you the result you're looking for.

这篇关于将mashape api响应转换为php字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆