CrazyLOL 2 Denunciar post Postado Março 13, 2015 Galera to com uma dúvida.. Segui um exemplo na internet de como acessar informações de um retorno em Json usando Json_decode pra criar um array.. porém está dando erro. Erro: Notice: Trying to get property of non-object Montei este script para teste, esqueci de algo? $teste = '{ "message": [ { "message_id": "72434", "destination": "553333333337", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72435", "destination": "553333333338", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72436", "destination": "553333333339", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72437", "destination": "5514900000000", 5 "status": "SENT" }, ] }'; //$_t = json_encode($teste); $_r = json_decode($teste); $msg = $_r->message; var_dump($msg); foreach ($msg as $a) { echo $a->message_id." ".$a->destination; } Compartilhar este post Link para o post Compartilhar em outros sites
William Bruno 1501 Denunciar post Postado Março 13, 2015 O json precisa ser válido <?php $teste = '{ "message": [ { "message_id": "72434", "destination": "553333333337", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72435", "destination": "553333333338", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72436", "destination": "553333333339", "status": "INVALID_DESTINATION_ADDRESS" }, { "message_id": "72437", "destination": "5514900000000", "status": "SENT" } ] }'; $json = json_decode($teste); $msg = $json->message; foreach ($msg as $each) { echo $each->message_id . ' ' . $each->destination . '<br />'; } existem alguns erros no teu json, por isso o decode não conseguia fazer o trabalho dele. Como um 5 perdido, uma virgula sobrando.. Saída: 72434 553333333337 72435 553333333338 72436 553333333339 72437 5514900000000 Compartilhar este post Link para o post Compartilhar em outros sites