API返回json。
$jsonData = '{"ResponseCode":200, "ResponseDetail":"Success", "AccessToken":"kksjfdlk"}{"ResponseCode":400, "ResponseDetail":"False"}';
如何访问ResponseCode
的价值?
答案 0 :(得分:0)
考虑到发布的字符串无效JSON,您可以使用ResponseCode
函数提取preg_match_all
值:
$jsonData = '{"ResponseCode":200, "ResponseDetail":"Success", "AccessToken":"kksjfdlk"}{"ResponseCode":400, "ResponseDetail":"False"}';
preg_match_all("/\"ResponseCode\"\s?:\s?(\d+)/", $jsonData, $m);
$response_codes = [];
// if there are matches
isset($m[1]) && $response_codes = $m[1];
print_r($response_codes);
输出:
Array
(
[0] => 200
[1] => 400
)