I have a JSON response, and I have tried many means to extract the value that has (APPROVED), but it is difficult
Here is the Response:
PHP, JSON
2028000NGNDepositSecure3D{"lkpTransactionId":"1100037249","lkpErrorNo":"0","lkpErrorDescription":"Approved","lkpEnrolled":"Y","lkpEciFlag":"02","authSend":"Y","authErrorNo":"0","authErrorDescription":"Approved","authCavv":"jHyn+7YFi1EUAREAAAAvNUe6Hv8=","authXid":"O0KGgwbJpRpdB8cw4OUfee34PkA=","authEciFlag":"02","authPAResStatus":"Y"}Successful64086914117475714319752028000052019545301******41541100037249MASTERCARDSamuel Adah00SuccessfultrueSUCCESSFULPAYMENT
I would like to get each results in an array or string.
THank you guys.
UPDATE:
I was able to follow your suggestion and I am left with the following results:
array(12) {
["lkpTransactionId"]=>
string(10) "1100037249"
["lkpErrorNo"]=>
string(1) "0"
["lkpErrorDescription"]=>
string(8) "Approved"
["lkpEnrolled"]=>
string(1) "Y"
["lkpEciFlag"]=>
string(2) "02"
["authSend"]=>
string(1) "Y"
["authErrorNo"]=>
string(1) "0"
["authErrorDescription"]=>
string(8) "Approved"
["authCavv"]=>
string(28) "jHyn+7YFi1EUAREAAAAvNUe6Hv8="
["authXid"]=>
string(28) "O0KGgwbJpRpdB8cw4OUfee34PkA="
["authEciFlag"]=>
string(2) "02"
["authPAResStatus"]=>
string(1) "Y"
}
Getting value of authErrorDescription is really difficult for me.
I tried this:
foreach($res as $user){
echo $user[8]['authErrorDescription'].'<br/>';
//echo $user[0]->authErrorDescription;
}
But result did not show properly.
That's not json in your example. Json starts with {
You can use this code for converting json into php Array
$res = json_decode('{"lkpTransactionId":"1100037249","lkpErrorNo":"0","lkpErrorDescription":"Approved","lkpEnrolled":"Y","lkpEciFlag":"02","authSend":"Y","authErrorNo":"0","authErrorDescription":"Approved","authCavv":"jHyn+7YFi1EUAREAAAAvNUe6Hv8=","authXid":"O0KGgwbJpRpdB8cw4OUfee34PkA=","authEciFlag":"02","authPAResStatus":"Y"}',true);
var_dump($res);
If you have that response (for any reasons) you have to parse this string before using json_decode.strpos($str,'{')
- will return position of '{' in your stringsubstr
- will return the portion of string that you need.
Eventually you should get somithing like that:
$res = json_decode(substr($yourString,strpos($yourString,'{'),strpos($yourString,'}') - strpos($yourString,'{')+1),true);