Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> json_decode dotarcie do danych z array
DannyM
post 16.07.2021, 10:43:57
Post #1





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Witajcie

Jak szybko dotrzeć do errorMessage?

  1.  
  2. foreach ( $json['failedOrders'] as $transfers ) {
  3.  
  4. foreach ( $transfers as $params ) {
  5. foreach ( $params as $insides ) {
  6. foreach ( $insides as $name => $value ) {
  7.  
  8. if ( $name == 'errorMessage') {
  9. echo $name;
  10. }
  11.  
  12.  
  13. }
  14. }
  15. }
  16. }
  17.  


coś mi tutaj nie działa jak trzeba sad.gif

  1. Array
  2. (
  3. [success] => 0
  4. [errors] => 1
  5. [createdOrders] => Array
  6. ()
  7.  
  8. [failedOrders] => Array
  9. (
  10. [0] => Array
  11. (
  12. [details] => Array
  13. (
  14.  
  15.  
  16. [errors] => Array
  17. (
  18. [0] => Array
  19. (
  20. [errorCode] => 25
  21. [errorMessage] => No channels were found
  22.  
  23.  
  24. )
  25.  
  26. )
  27.  
  28. )
  29.  
  30. )
  31.  
  32. )


W efekcie dostaję

ArrayArrayNo channels were found

Ten post edytował DannyM 16.07.2021, 10:57:12
Go to the top of the page
+Quote Post
nospor
post 16.07.2021, 10:50:38
Post #2





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Bo masz tablice obiektow a nie tablice tablic. Nie widzisz?
Jak chcesz miec tablice, to uzyj drugiego parametru w json_decode


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
DannyM
post 16.07.2021, 10:53:17
Post #3





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 16.07.2021, 12:50:38 ) *
Bo masz tablice obiektow a nie tablice tablic. Nie widzisz?
Jak chcesz miec tablice, to uzyj drugiego parametru w json_decode


Ten Json podałem tylko aby pokazać zagłębienie smile.gif {zmieniłem}

Ten post edytował DannyM 16.07.2021, 10:59:08
Go to the top of the page
+Quote Post
Pyton_000
post 16.07.2021, 11:35:25
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Zamiast bawić się w foreache to użyj https://github.com/Galbar/JsonPath-PHP

i pattern coś na zasadzie

Kod
$.failedOrders..errorMessage[*]
Go to the top of the page
+Quote Post
nospor
post 16.07.2021, 15:18:55
Post #5





Grupa: Moderatorzy
Postów: 36 455
Pomógł: 6292
Dołączył: 27.12.2004




Przekombinowales

  1. foreach ( $json['failedOrders'] as $order ) {
  2.  
  3. foreach ( $order['errors'] as $error ) {
  4. echo $error['message'];
  5. }
  6. }

I juz


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
DannyM
post 19.07.2021, 11:00:17
Post #6





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


Cytat(nospor @ 16.07.2021, 17:18:55 ) *
Przekombinowales

  1. foreach ( $json['failedOrders'] as $order ) {
  2.  
  3. foreach ( $order['errors'] as $error ) {
  4. echo $error['message'];
  5. }
  6. }

I juz


Dziękuję jak zawsze można na Ciebie liczyć
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 11:10