Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Recupero informazione json

    Salve come da titolo ho questo response json :

    codice:
    stdClass Object ( [result] => OK [credits] => Array ( [0] => stdClass Object ( [message-type] => N [amount] => 7 ) [1] => stdClass Object ( [message-type] => L [amount] => 43 ) [2] => stdClass Object ( [message-type] => LL [amount] => 0 ) [3] => stdClass Object ( [message-type] => EE [amount] => 7 ) [4] => stdClass Object ( [message-type] => AD [amount] => 7 ) ) )
    mettiamo conto che lo inserisca nella variabile $a

    se faccio print_r di $a->credits ho tutti gli array all'interno , io vorrei prendere il valore di amount dentro 0 dentro credits ,

    se faccio $a->credits->0->amount

    ho :

    syntax error, unexpected '0'

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Credits è un array non uno stdClass Object, quindi credits[0]

  3. #3
    Passa true come secondo parametro a json_decode() così ottieni un array associativo invece di un oggetto e gestisci tutto in modo coerente (attraverso gli array).

    https://www.php.net/json_decode

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.