Php JSON解码转换为整数,但未给出预期结果

Php JSON解码转换为整数,但未给出预期结果,php,Php,我正在从这样的Web服务中解码JSON,对于$rspcode,我正在转换为integer,并检查switch语句是否响应为00(这是一个整数)。请问我做错了什么,因为我没有得到想要的输出 $context = stream_context_create($opts); // Open the file using the HTTP headers set above $response = file_get_contents($url, false, $context); //done $de

我正在从这样的Web服务中解码JSON,对于$rspcode,我正在转换为integer,并检查switch语句是否响应为00(这是一个整数)。请问我做错了什么,因为我没有得到想要的输出

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$response = file_get_contents($url, false, $context); //done
$decoder = json_decode($response);
$rspcode        = $decoder->{'ResponseCode'};
$rspamount      = $decoder->{'Amount'};
$rspcardno      = $decoder->{'CardNumber'};
$rspmerchant    = $decoder->{'MerchantReference'};
$rsppayref      = $decoder->{'PaymentReference'};
$rsprefnumber   = $decoder->{'RetrievalReferenceNumber'};
$rsptransdate   = $decoder->{'TransactionDate'};
$rspdescription = $decoder->{'ResponseDescription'};



 switch(intval($rspcode))
    {
        case "00":
    //do something
    break;
    default:
    break;
    }

intval('00')
将是0,而不是00。您还可以改进您的案例,但不使其成为字符串,但由于switch使用松散比较
0
“0”
在技术上仍然有效
00
不是整数
0
是。@NiettheDarkAbsol这是服务返回的值,他们希望它被视为int。不知道为什么要使用
intval
,然后使用
case
对字符串进行排序。你真的认为这样行吗?