简体   繁体   中英

Split array into strings

I am in the process of creating a website that ges informatin from an API that responds in JSON-format. I would like to execute the following command in PHP:

exec('curl -v -u {client_id}:{client_secret} -d code="{authorization_code}" -d redirect_uri={redirect_uri} -d grant_type=authorization_code https://api.basespace.illumina.com/v1pre3/oauthv2/token', $token);

This returns an array called $token which contains something of the following format:

Array ( [0] => {"error":"invalid_grant","error_description":"Authorization code is unknown for this application or an access token has already been issued for it."} )

In this example I would like to put the error and the error_description in seperate variables, for further processing. I already thought of using substr() , but the content of $token can vary, so I think that won't work... Is there another, more simple way to split the array?

$arr = json_decode($token[0], true); //not a very indicative name for JSON, 'token'
$error = $arr['error'];
$error_desc = $arr['error_description'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM