3
UPDATE
I found this answer from Soen, on the link suggested by @Pedrox, talks about Reflection, would be applicable to this case as well?
As I have been told here on Sopt, i was trying to convert a list of objects to json. Well, now I need to recover this list from json to an array of objects.
The problem is that the json_decode
, as it says to documentation, me returns an array of a special object called stdObject
or an associative array, in my case this:
Array
(
[0] => Array
(
[Corrente] => Array
(
[tarifaManutencao] => 12.5
[numero] => 123
[proprietario] => teste
[saldo] => 3.1
[permissoesEspeciaisHabilitadas] =>
)
)
[1] => Array
(
[Poupanca] => Array
(
[quantidadeConsultas] => 0
[numero] => 456
[proprietario] => testeprop
[saldo] => 50
[permissoesEspeciaisHabilitadas] =>
)
)
[2] => Array
(
[Especial] => Array
(
[limite] => 500
[valorEmprestado] => 0
[jurosCobrados] => 0
[tarifaManutencao] => 20
[numero] => 789
[proprietario] => teste4
[saldo] => 100
[permissoesEspeciaisHabilitadas] =>
)
)
)
What I needed was to return the array as a list of objects, similar to the functions serialize
and unserialize
do. I saw in this topic that in java has how to do this, passing the json
and the POJO class of the custom object for a lib method Gson
, and it converts automatically, and also that I can do this using a foreach
or for
.
It is possible to retrieve my Current, Save and Special json objects in a similar way to java?
The problem you have is you can’t call the methods
sacar()
,depositar()
,cobrarTarifa()
for example?– rray
@rray did not understand, how so?
– user28595
For example if you do a foreach and inside it call the
sacar()
regardless of account type, does it work? or error?– rray
@rray believe so, because in the foreach I would have to keep giving
new
in the object according to the type and setting the attributes in the constructor.– user28595