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>";}

avatar candra1098
@candra1098

41 Kontribusi 10 Poin

Diperbarui 2 tahun yang lalu

2 Jawaban:

<div>Hai&nbsp;<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-&gt;data-&gt;status-&gt;orders as $objectlist) { echo $objectlist-&gt;complete-&gt;merchant_invoice."&lt;br&gt;";}</pre><div><br>untuk full scriptnya kamu bisa coba source code di bawah ini<br><br></div><pre>$result = json_decode($isJson);

foreach($result-&gt;data-&gt;orders as $objectlist) { if(is_array($objectlist-&gt;complete)) {
foreach($objectlist-&gt;complete as $objeclistRes) { echo $objeclistRes-&gt;merchant_invoice."&lt;br&gt;"; } } else { echo $objectlist-&gt;complete-&gt;merchant_invoice."&lt;br&gt;"; } }</pre><div><br>Semoga Membantu ya :)</div>

avatar tantootnat
@tantootnat

14 Kontribusi 11 Poin

Dipost 2 tahun yang lalu

<div>@tantootnat<br>Terimakasih banyak mas,sudah bisa.<br>Semoga rejeki nya lancar mas</div>

avatar candra1098
@candra1098

41 Kontribusi 10 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban