Gonçalo Paiva Posted May 4, 2015 at 02:33 PM Report Share #582437 Posted May 4, 2015 at 02:33 PM (edited) Olá Forum, estou a fazer uma solicitação a um web service ao qual me retorna o seguinte: object(stdClass)#2 (2) { ["currentAccountDocs"]=> array(8) { [0]=> object(stdClass)#3 (7) { ["docName"]=> string(7) "Factura" ["docNumber"]=> string(6) "A13/58" ["docDate"]=> string(10) "2013-02-25" ["docCreditAmount"]=> float(399.75) ["docDebitAmount"]=> float(0) ["docPaidAmount"]=> float(0) ["docDueDate"]=> string(10) "2013-02-25" } [1]=> object(stdClass)#4 (7) Alguma ideia de como posso chegar aos valores de cada objecto e imprimi-los no ecra? ( Factura, A13/58, 2013-02-25 ... ) Tentei correr o vector assim, mas nada me aparece no ecrã. foreach($response as $key =>$object){ echo $object->docName." ".$object->docNumber." ".$object->docDate." ".$object->docCreditAmount." "; } ?> Edited May 4, 2015 at 06:03 PM by apocsantos tag code + geshi Link to comment Share on other sites More sharing options...
help Posted May 4, 2015 at 02:40 PM Report Share #582439 Posted May 4, 2015 at 02:40 PM (edited) Isso não parece um simples array. Você pode tentar um explode para pegar o elemento que precisa. <?php $valores ='object(stdClass)#2 (2) { ["currentAccountDocs"]=> array(8) { [0]=> object(stdClass)#3 (7) { ["docName"]=> string(7) "Factura" ["docNumber"]=> string(6) "A13/58" ["docDate"]=> string(10) "2013-02-25" ["docCreditAmount"]=> float(399.75) ["docDebitAmount"]=> float(0) ["docPaidAmount"]=> float(0) ["docDueDate"]=> string(10) "2013-02-25" } [1]=> object(stdClass)#4 (7)'; $valor = explode("string(6) \"", $valores); $valor2 = explode("\"", $valor[1]); echo $valor2[0]; ?> Edited May 4, 2015 at 06:03 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
Solution bioshock Posted May 4, 2015 at 03:55 PM Solution Report Share #582443 Posted May 4, 2015 at 03:55 PM E não te lembraste de formatar a informação que te é retornada? É que isso que nos colocaste é de difícil leitura se não houver a respectiva formatação. object(stdClass)#2 (2) { ["currentAccountDocs"]=> array(8) { [0]=> object(stdClass)#3 (7) { ["docName"]=> string(7) "Factura" ["docNumber"]=> string(6) "A13/58" ["docDate"]=> string(10) "2013-02-25" ["docCreditAmount"]=> float(399.75) ["docDebitAmount"]=> float(0) ["docPaidAmount"]=> float(0) ["docDueDate"]=> string(10) "2013-02-25" } [1]=> object(stdClass)#4 (7) { ["docName"]=> string(7) "Factura" ["docNumber"]=> string(6) "A13/58" ["docDate"]=> string(10) "2013-02-25" ["docCreditAmount"]=> float(399.75) ["docDebitAmount"]=> float(0) ["docPaidAmount"]=> float(0) ["docDueDate"]=> string(10) "2013-02-25" } } } Então, isto significa que tens de aceder primeiro ao índice array $response->currentAccountDocs para que possas percorrer todos os elementos dentro. 1 Report Link to comment Share on other sites More sharing options...
Gonçalo Paiva Posted May 4, 2015 at 04:04 PM Author Report Share #582446 Posted May 4, 2015 at 04:04 PM Desculpa e Obrigado. Resolvido. Link to comment Share on other sites More sharing options...
RuiAlmeida20 Posted May 4, 2015 at 04:51 PM Report Share #582448 Posted May 4, 2015 at 04:51 PM exprimenta: foreach($response->currentAccountDocs as $object) { echo $object->docName . $object->docNumber. $object->docDate. $object->docCreditAmount ; } 1 Report Link to comment Share on other sites More sharing options...
Gonçalo Paiva Posted May 5, 2015 at 02:06 PM Author Report Share #582499 Posted May 5, 2015 at 02:06 PM É isso mesmo Rui. Obrigado. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now