How to convert PHP object array to JSON

Asked

Viewed 40 times

1

I am trying to learn Angularjs and today I have a PHP5 application, but I am not using Restful. For testing purposes I want to run my query and fill a table with the result using Angularjs. My problem is that I run the search inside the class through the method I created, and it obviously returns an array with each object and its properties according to the query. I searched and tried using the following line to convert my array to JSON and use Angularjs, but my return is being empty.

$cervejas = new Cerveja();
$lista = $tt->listar();
echo json_encode($lista);

But then I couldn’t print my object array. PS: if I give one

print_r ($lista);

The array has the contents.

Array ( 
[0] => Cerveja Object ( [id:Cerveja:private] => 2 [nomeCerveja:Cerveja:private] => Cerveja 1 ) 
[1] => Cerveja Object ( [id:Cerveja:private] => 3 [nomeCerveja:Cerveja:private] => Cerveja 2 ) 
[2] => Cerveja Object ( [id:Cerveja:private] => 6 [nomeCerveja:Cerveja:private] => Cerveja 3 ) 
) 
  • You can show the return of $lista? $beras is there pq hj is sixth? xD

  • @rray added the result. [off]All examples look better with beer[/off]

  • Private attributes are not converted in json, already have a question about that already think she.

  • 2

    I think it solves, Convert json object in php

  • @rray I know that question there. : p

No answers

Browser other questions tagged

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