下面是我的工作 api,但结果为"echo $data"
is only"array"
和 for "echo $data["data"]["operatorid"]"
is nothing 屏幕变为空白。那么如何转换json reponse
为php
字符串并从中获取特定值
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-Mashape-Key: XXXXXXXX"
)
);
$context = stream_context_create($opts);
$res = file_get_contents('https://tariff-plan-api-datayuge.p.mashape.com/index.php?circleid=kerala&limit=50&operatorid=BSNL&recharge_type=top', false, $context);
$data = (json_decode($res, true));
echo $data["data"]["operatorid"];
json响应:
{
"data": [
{
"id": "3148",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "150",
"recharge_talktime": "150",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 150 By BSNL",
"recharge_longdesc": "Full Talktime (offer valid upto 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3149",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "250",
"recharge_talktime": "250",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 250 By BSNL",
"recharge_longdesc": "Full Talktime (offer valid upto 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3150",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "550",
"recharge_talktime": "550",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 550 By BSNL",
"recharge_longdesc": "Full Talktime (offer valid upto 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3151",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "1000",
"recharge_talktime": "1100",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 1000 By BSNL",
"recharge_longdesc": "Extra Talktime (offer is valid till 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3152",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "1100",
"recharge_talktime": "1210",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 1100 By BSNL",
"recharge_longdesc": "Extra Talktime (offer is valid till 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3153",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "1500",
"recharge_talktime": "1650",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 1500 By BSNL",
"recharge_longdesc": "Extra Talktime (offer is valid till 23 Mar 2015)",
"recharge_type": "Full Talktime"
},
{
"id": "3154",
"operatorid": "BSNL",
"circleid": "Kerala",
"recharge_amount": "2000",
"recharge_talktime": "2200",
"recharge_validity": "Unlimited",
"recharge_shortdesc": "Recharge Of Rs 2000 By BSNL",
"recharge_longdesc": "Extra Talktime (offer is valid till 23 Mar 2015)",
"recharge_type": "Full Talktime"
}
]