如何从 curl 响应中读取特定值

How to read Specific value from curl Response

这是我的回复

我需要读取沙盒的第一行 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/" } }

假设您在名为 $resp

的变量中收到来自 curl 的响应
$resp_decoded = json_decode($resp,TRUE);
print($resp_decoded['id']);
print($resp_decoded['transaction']['url']);