0
I got the following return of PHP for JSON through AJAX:
[
"ok",
[
[
{
"\u0000CelulasReunioes\u0000idCelula":"17",
"\u0000CelulasReunioes\u0000data":"2019-01-30",
"\u0000CelulasReunioes\u0000presentes":"0",
"\u0000CelulasReunioes\u0000visitas":"0",
"\u0000CelulasReunioes\u0000criancas":"0",
"\u0000CelulasReunioes\u0000decisoes":"0",
"\u0000CelulasReunioes\u0000discipulados":"0",
"\u0000CelulasReunioes\u0000jejum":"s",
"\u0000CelulasReunioes\u0000evangelismo":"s",
"\u0000CelulasReunioes\u0000supervisao":"s",
"\u0000CelulasReunioes\u0000oferta":"30"
},
{
"\u0000CelulasReunioes\u0000idCelula":"17",
"\u0000CelulasReunioes\u0000data":"2019-02-01",
"\u0000CelulasReunioes\u0000presentes":"10",
"\u0000CelulasReunioes\u0000visitas":"2",
"\u0000CelulasReunioes\u0000criancas":"2",
"\u0000CelulasReunioes\u0000decisoes":"6",
"\u0000CelulasReunioes\u0000discipulados":"1",
"\u0000CelulasReunioes\u0000jejum":"n",
"\u0000CelulasReunioes\u0000evangelismo":"n",
"\u0000CelulasReunioes\u0000supervisao":"n",
"\u0000CelulasReunioes\u0000oferta":"0"
}
]
]
]
I basically made a (array) $objeto
in the PHP to use json_encode ()
for they are returns of PHP objects
Now, I intend to use that array of 2 positions`
retorno [ 0 ] = "ok";
retorno [ 1 ] = array PHP de objetos convertidos por (array) com vários índices;
Catch the position [ 1 ] of array and make a foreach
.
resultado.forEach(function(reuniao, index){
html = '<h2>' + reuniao.idCelula + '</h2>';
html += '<ul class="vertical">';
html += ' <li><label class="labelPequeno">Data</label> : ' + reuniao.data + '</li>';
html += '</ul>';
});
Obs.:
My purpose here is to transform the return:
"\u0000CelulasReunioes\u0000idCelula"
in
"CelulasReunioesidCelula"
and, if possible, preferably:
"idCelula"
Can someone help me?
Have you managed to do the ajax part? Where, here in the question, is some jQuery method, as you quote in the title? I didn’t quite understand "where you’re struggling"...
– LipESprY
Yes: the part that is like this: "u0000Cellulars u0000idCellular":"17", is already the return of the ajax. Here it is normal. Now I need to transform that return that comes out on the console like this : Cellulasreunions idCellular, that in jQuery. Realize that u0000 means a blank space
– Carlos Rocha
CelulasReunioes
is the name of your class in PHP? If so, how did you form this JSON? From what I understand, your problem lies in the formation of JSON. You better fix this in PHP, don’t you think? What do you think of [Edit] the question and post your PHP code, if applicable?– LipESprY
(array) $object. So I formed the PHP array, but it delivers something like this " u0000CelulasReunions u0000idCelula":"17". for the incus. It puts a space before and after the name of the Class
– Carlos Rocha
Does it serve you an answer that "corrects" your PHP? When I say correct, it means doing it another way which I think is more appropriate. Then you judge if it’s better for your application...
– LipESprY
yes, but it would be by converting the object to an array attribute by attribute or there is a more direct function like what does the (array) $object°
– Carlos Rocha
My answer already explains and exemplifies it. I confess that I am still curious! How did you manage to get to a JSON with the class name on each attribute? I tried to imitate your JSON but could not! @_@
– LipESprY
as I explained, I converted objects into array with the function (array) $object.
– Carlos Rocha
Let’s go continue this discussion in chat.
– LipESprY