【问题标题】:How to read Specific value from curl Response如何从 curl 响应中读取特定值
【发布时间】:2019-11-08 02:40:48
【问题描述】:

这是我的回应

我需要读取沙盒的第一行 id 值和 url

{ 
 "id": "chg_g5Y25220190539Ob590811651", 
 "object": "charge",
 "live_mode": false,
 "api_version": "V2",
 "method": "CREATE",
 "status": "INITIATED",
 "amount": 1.000,
 "currency": "KWD",
 "threeDSecure": false,
 "card_threeDSecure": false,
 "save_card": false,
 "statement_descriptor": "Sample",
 "description": "Test DESC",
 "transaction": 
  {
    "timezone": "UTC+03:00",
    "created": "1573191592651",
    "url": "https://sandbox.payments.tap.company/test_gosell/v2/payment/response.aspx?tap_chg=PsV8hZdr78kEIAOZl9XL1B5u3dXe%2bBQ%2b3Hrd%2fempxYs%3d&sess=noWi606EI%2bM%3d&token=PsV8hZdr78kEIAOZl9XL1B5u3dXe%2bBQ%2bTyYdQy9iGpS6aAXwKOqAdw%3d%3d",
    "expiry": { "period": 30, "type": "MINUTE" },
    "asynchronous": false
  },
 "reference": { "transaction": "txn_0001", "order": "ord_0001" },
 "response":  { "code": "100", "message": "Initiated" },
 "receipt":   { "email": true, "sms": true },
 "customer":  { "first_name": "yxy", "last_name": "ttt", "email": "xyx@xyz.com" },
 "source":    { "object": "source", "id": "src_card" },
 "redirect": { "status": "PENDING", "url": "http://localhost:81/School/" },
 "post": { "status": "PENDING", "url": "http://localhost:81/School/" } }

【问题讨论】:

    标签: php arrays json api php-curl


    【解决方案1】:

    假设您在名为 $resp 的变量中收到来自 curl 的响应

    $resp_decoded = json_decode($resp,TRUE);
    print($resp_decoded['id']);
    print($resp_decoded['transaction']['url']);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-03
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多