从API返回的解析json

问题描述:

API返回以下json。从API返回的解析json

$jsonData = '{"ResponseCode":200, "ResponseDetail":"Success", "AccessToken":"kksjfdlk"}{"ResponseCode":400, "ResponseDetail":"False"}'; 

如何获取ResponseCode的值?

+0

*过滤通过* - 你有什么过滤? – RomanPerekhrest

+0

我想输出一个ResponseCode $ json = json_decode($ jsonData); $ json-> ResponseCode; –

+0

问题太广泛,不清楚。 –

考虑到张贴的字符串不是有效的JSON可以提取使用preg_match_all功能ResponseCode值:

$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 
)