dpb42021 2019-05-04 11:37
浏览 11
已采纳

从SOAP / JSON中提取值

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.

  • 写回答

1条回答 默认 最新

  • duanjiaoxi4928 2019-05-04 12:01
    关注

    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 string
    substr - 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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大