Postingan lainnya
Bagaimana cara mengambil data json menggunakan perulangan php
datanyaBagaimana jika saya ingn mengambil data merchan_invoice, merchant_id, transaction_amount, dan transaction_date
2 Jawaban:
<div>Decode dulu jd array lakukan sisanya penelusuran data array dan looping data tersebut<br><br></div>
Jawaban Terpilih
<div>Gunakan json_decode
dari php untuk mengdecode atau mengekstrak json datanya<br><br></div><pre><?php
$json = '{
"data": {
"status": 200,
"orders": [{
"complete": [{
"merchant_invoice": "111111",
"merchant_id": "1",
"transaction_amount": "10.500",
"transaction_time": "17:44:20"
},
{
"merchant_invoice": "111111",
"merchant_id": "1",
"transaction_amount": "10.500",
"transaction_time": "17:44:20"
},
{
"merchant_invoice": "111111",
"merchant_id": "1",
"transaction_amount": "10.500",
"transaction_time": "17:44:20"
}]
}]
}
}';
$json_array = json_decode($json, true);
$arr = $json_array['data']['orders'][0]['complete'];
<em>foreach</em>($arr as $key=>$value){ echo "merchant_invoice : " . $value['merchant_invoice'] . " "; echo "merchant_id : " . $value['merchant_id'] . " "; echo "transaction_amount : " . $value['transaction_amount'] . " "; echo "transaction_time : " . $value['transaction_time'] . " "; } <br></pre><div><br></div>