duanfei8149
2015-07-18 07:18
浏览 53
已采纳

json响应空间不转换为php对象

Below is my working code but when I am trying to echo "Telecom circle", getting error "Parse error: syntax error, unexpected 'circle' (T_STRING)".

if ($_GET['result']):
$rslt = $_GET['result'];
$result = Unirest\Request::get("https://sphirelabs-mobile-number-portability-india-operator-v1.p.mashape.com/index.php?number=$rslt",
array(
"X-Mashape-Key" => "XXXXXXXXXXXXX",
"Accept" => "application/json"
)
);

echo ($result->body->Operator);
echo($result->body->Telecom circle);
endif;  

API RESPONSE :

{
"Telecom circle": "Delhi NCR",
"Operator": "Vodafone",
"Is MNP": "False"
}

图片转代码服务由CSDN问答提供 功能建议

下面是我的工作代码,但当我试图回应“电信圈”时,收到错误“Parse error:syntax 错误,意外'圈'(T_STRING)“。

  if($ _GET ['result']):
 $ rslt = $ _GET ['result']; \  n $ result = Unirest \ Request :: get(“https://sphirelabs-mobile-number-portability-india-operator-v1.p.mashape.com/index.php?number=$rslt”,
array(\  n“X-Mashape-Key”=>“XXXXXXXXXXXXX”,
“接受”=>“application / json”
)
); 
 
echo($ result-> body-> Operator  ); 
echo($ result-> body-> Telecom circle); 
endif;  
   
 
 

API响应:

  {
“Telecom circle”:“Delhi NCR”,
“ 运算符“:”Vodafone“,
”是MNP“:”False“
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhao9203 2015-07-18 07:27
    已采纳

    Your code should be :

    Just used $result->body->{'Telecom circle'} instead of $result->body->Telecom circle

    if ($_GET['result']):
    $rslt = $_GET['result'];
    $result = Unirest\Request::get("https://sphirelabs-mobile-number-portability-india-operator-v1.p.mashape.com/index.php?number=$rslt",
    array(
    "X-Mashape-Key" => "XXXXXXXXXXXXX",
    "Accept" => "application/json"
    )
    );
    
    echo ($result->body->Operator);
    echo($result->body->{'Telecom circle'});
    endif;  
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题