4

I´m getting a ParseObject from a query and I need to convert it into json.

When I do a print_r($results) I get a lot of stuff but when I do $json = json_encode($results) and print it, the $json is empty.

Here is the var_dump of $results:

array (size=5)
  0 => 
    object(Parse\ParseObject)[12]
      protected 'serverData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[15]
              ...
      protected 'operationSet' => 
        array (size=0)
          empty
      private 'estimatedData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[15]
              ...
      private 'dataAvailability' => 
        array (size=1)
          'Usuario_FK' => boolean true
      private 'className' => string 'Asistencia' (length=10)
      private 'objectId' => string 'mdHR3ZZo6z' (length=10)
      private 'createdAt' => 
        object(DateTime)[13]
          public 'date' => string '2015-06-10 01:17:13' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'updatedAt' => 
        object(DateTime)[14]
          public 'date' => string '2015-06-13 13:34:05' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'hasBeenFetched' => boolean false
  1 => 
    object(Parse\ParseObject)[21]
      protected 'serverData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[24]
              ...
      protected 'operationSet' => 
        array (size=0)
          empty
      private 'estimatedData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[24]
              ...
      private 'dataAvailability' => 
        array (size=1)
          'Usuario_FK' => boolean true
      private 'className' => string 'Asistencia' (length=10)
      private 'objectId' => string '3DK19BWOYY' (length=10)
      private 'createdAt' => 
        object(DateTime)[22]
          public 'date' => string '2015-06-10 01:08:14' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'updatedAt' => 
        object(DateTime)[23]
          public 'date' => string '2015-06-13 13:34:09' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'hasBeenFetched' => boolean false
  2 => 
    object(Parse\ParseObject)[30]
      protected 'serverData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[33]
              ...
      protected 'operationSet' => 
        array (size=0)
          empty
      private 'estimatedData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[33]
              ...
      private 'dataAvailability' => 
        array (size=1)
          'Usuario_FK' => boolean true
      private 'className' => string 'Asistencia' (length=10)
      private 'objectId' => string 'x94VIvFpdq' (length=10)
      private 'createdAt' => 
        object(DateTime)[31]
          public 'date' => string '2015-06-10 01:07:38' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'updatedAt' => 
        object(DateTime)[32]
          public 'date' => string '2015-06-13 13:34:11' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'hasBeenFetched' => boolean false
  3 => 
    object(Parse\ParseObject)[39]
      protected 'serverData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[42]
              ...
      protected 'operationSet' => 
        array (size=0)
          empty
      private 'estimatedData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[42]
              ...
      private 'dataAvailability' => 
        array (size=1)
          'Usuario_FK' => boolean true
      private 'className' => string 'Asistencia' (length=10)
      private 'objectId' => string 'z4vtVb9sdU' (length=10)
      private 'createdAt' => 
        object(DateTime)[40]
          public 'date' => string '2015-06-10 01:13:05' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'updatedAt' => 
        object(DateTime)[41]
          public 'date' => string '2015-06-13 13:34:07' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'hasBeenFetched' => boolean false
  4 => 
    object(Parse\ParseObject)[48]
      protected 'serverData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[51]
              ...
      protected 'operationSet' => 
        array (size=0)
          empty
      private 'estimatedData' => 
        array (size=1)
          'Usuario_FK' => 
            object(Parse\ParseUser)[51]
              ...
      private 'dataAvailability' => 
        array (size=1)
          'Usuario_FK' => boolean true
      private 'className' => string 'Asistencia' (length=10)
      private 'objectId' => string 'LRsOGB7mjZ' (length=10)
      private 'createdAt' => 
        object(DateTime)[49]
          public 'date' => string '2015-06-10 03:13:36' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'updatedAt' => 
        object(DateTime)[50]
          public 'date' => string '2015-06-13 14:01:03' (length=19)
          public 'timezone_type' => int 2
          public 'timezone' => string 'Z' (length=1)
      private 'hasBeenFetched' => boolean false

And here is after json_encode($results);

[{},{},{},{},{}]

Ideas?

Thank you for your time!

Vorenus
  • 65
  • 6
  • show the `var_dump($yourparseobect);` – Iqbal Rizky Jun 14 '15 at 01:23
  • Is `$result` an object? If that's the case then [this](http://stackoverflow.com/questions/6836592/serializing-php-object-to-json) might help you. – Ulver Jun 14 '15 at 02:36
  • @ntaloventi I edited the post with the information. I think that the problem is that json_encode does not work with private/protected elements. I am trying to change that properties and try to do the encode. – Vorenus Jun 15 '15 at 13:49

0 Answers0