Data Return from an API

Asked

Viewed 46 times

0

I’m integrating with an email marketing system. Data returns are coming in standard:

Array(
[0] => Criaenvio\Grupo Object
    (
        [nome] => Geral
        [ativo] => 1
        [contatos_ativos] => 0
        [id] => JCp
        [_tipoSolicitacao:protected] => 1
        [_caminho:protected] => 
        [_parametros:protected] => Array
            (
            )

        [_parametrosURL:protected] => Array
            (
            )

    )

[1] => Criaenvio\Grupo Object
    (
        [nome] => Lista Teste
        [ativo] => 1
        [contatos_ativos] => 0
        [id] => JCG
        [_tipoSolicitacao:protected] => 1
        [_caminho:protected] => 
        [_parametros:protected] => Array
            (
            )

        [_parametrosURL:protected] => Array
            (
            )
    )
)

The result is always presented in groups of 2 with the same structure. I am not able to access the data presented. I need to access the name for example. I tried several ways as $dados[0]['nome'] and I can’t access data values.

I need to put this data into one <select>.

  • try it like this: $dados[0]->nome

  • @Danielomine Thanks! I had tried as object also before, but does not return/print anything.

  • @lelopes put the information before you arrive in this array!

  • @Danielomine. the answer to the request made for API is the code above in the question. I gave a var_dump and presented the answer.

  • this presented is probably the result of a var_dump(). It is used for testing only. Remove the var_dump() and treat API return normally.

1 answer

0


Try doing as @Daniel Omine suggested. $dados[0]->nome.

Apparently you have an array of objects and in the PHP array you access this way: $var["chave"] and object you access so: $obj->atributo.

  • did not work. I had tried this before. I forgot to put in the question.

  • Sends a var_dump of your array and the way you’re iterating on it.

  • The above result is already a var_dump is the result of the API response

  • the API should return this as correct JSON? How do you convert to array? Can you provide the API or return JSON?

  • I found the personal error, was overwriting variable. Very much the brigadier Anderson and Virgilio.

  • Dispo @lelopes :)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.