To create the contents of a file JSON
, first we create a array
:
$meus_dados = array();
After we have a array
created we must popular this array
:
for ($i = 0; $i < 3; $i++) {
$meus_dados[$i]['nome'] = "nome".($i + 1);
$meus_dados[$i]['email'] = "email".($i + 1);
$meus_dados[$i]['id'] = "id".($i + 1);
}
Now that we have ours array
populated, we have to use the function json_encode
to generate a JSON
that array
:
echo json_encode($meus_dados);
Upshot
[{"name":"name1","email":"Email1","id":"id1"},
{"name":"Nome2","email":"Email2","id":"id2"},
{"name":"name3","email":"email3","id":"id3"}]
You can start with the function json_encode() If you have more details edit the question.
– rray
you want to take the data cia database and using PHP to convert the data to json?
– DNick
Dude you should make a select in the database, with PHP for example, and this return you send via json_encode()... and you can work it in the app or javascript..
– wDrik
I would sort of select to bring the results as if I were going to do with an echo, but instead echo uses json_enconde?
– Leandro Teraoka