Postingan lainnya
Cara parsing data json
Hallo teman,mungkin ada yang tau cara parsing data Jason berikut:
{"data":{"status":200,"orders":[{"complete":[{"merchant_invoice":"111","merchant_id":"15527","merchant_name":"yys","transaction_date":"2021-11-29","transaction_time":"05:23:18","card_no":"800999xxxxxx1001","transaction_amount":1000.00,"transaction_fee":0.00,"transaction_amount_text":"0","ovo_earn":0,"ovo_used":0,"emoney_used":1000.00,"emoney_topup":0,"emoney_bonus":0,"emoney_used_text":"0","emoney_topup_text":"0","emoney_bonus_text":"0","desc1":"yys Dompet Umat (Infaq)","desc2":"Pembayaran","desc3":"","status":"PENDING","ui_type":1,"transaction_type":"QRIS ISS PURCHASE","transaction_type_id":38,"icon_url":"15527","category_id":0,"category_name":"-"}],"pending":[]}],"message":""},"response_code":"OV00000","response_message":"Success","response_version":"1"}
Yang sudah saya coba dan gagal
$arrayorder = json_decode($data);
foreach ($arrayorder->data->status->orders as $objectlist) { echo
$objectlist->complete->merchant_invoice."<br>";}
2 Jawaban:
<div>Hai <a href="https://sekolahkoding.com/user/candra1098">@candra1098</a><br><br>Cara kamu sudah benar, cuman ada kelebihan pemanggilan object saat looping<br><br></div><pre>foreach ($arrayorder->data->status->orders as $objectlist) { echo $objectlist->complete->merchant_invoice."<br>";}</pre><div><br>untuk full scriptnya kamu bisa coba source code di bawah ini<br><br></div><pre>$result = json_decode($isJson);
foreach($result->data->orders as $objectlist) {
if(is_array($objectlist->complete)) {
foreach($objectlist->complete as $objeclistRes) {
echo $objeclistRes->merchant_invoice."<br>";
}
} else {
echo $objectlist->complete->merchant_invoice."<br>";
}
}</pre><div><br>Semoga Membantu ya :)</div>
<div>@tantootnat<br>Terimakasih banyak mas,sudah bisa.<br>Semoga rejeki nya lancar mas</div>