json - parse.com nested objects _encode() and decode to php array not working properly -


i have parseobject called follow explained in js tutorial https://parse.com/docs/js/guide#relations-using-join-tables

although i'm doing in php. goal once follow object saved able php array representation of object nested classes. from , to properties of follow object pointers _user object.

this block of code create follow object, attempts convert object php array using json_decode, top level object correctly decoded.

public function post_follow() {     try {          $user = $this->get_user(input::post('objectid'));          $follow = new parseobject("follow");         $follow->set("from", $this->currentuser);         $follow->set("to", $user);         $follow->save();          $this->output = json_decode($follow->_encode(),true);     }     catch(parseexception $ex) {          return $this->error($ex);     } } 

where $this->output php array later turned json via framework.

this method has output

    {   "objectid": "6gb1wflpfw",   "createdat": {     "date": "2015-08-16 22:29:48.445000",     "timezone_type": 2,     "timezone": "z"   },   "updatedat": {     "date": "2015-08-16 22:29:48.445000",     "timezone_type": 2,     "timezone": "z"   },   "from": "{\"objectid\":\"88d437qdxp\",\"createdat\":{\"date\":\"2015-08-13 08:26:29.478000\",\"timezone_type\":2,\"timezone\":\"z\"},\"updatedat\":{\"date\":\"2015-08-16 20:09:17.048000\",\"timezone_type\":2,\"timezone\":\"z\"},\"email\":\"brian@mail.com\",\"emailverified\":true,\"followerscount\":1,\"followingcount\":2,\"friendscount\":18,\"phone\":null,\"username\":\"brian\"}",   "to": "{\"objectid\":\"cmx8o9sedh\",\"createdat\":{\"date\":\"2015-08-13 08:29:54.735000\",\"timezone_type\":2,\"timezone\":\"z\"},\"updatedat\":{\"date\":\"2015-08-13 08:30:17.188000\",\"timezone_type\":2,\"timezone\":\"z\"},\"email\":\"brian+2@mail.com\",\"emailverified\":true,\"phone\":null,\"username\":\"brian2\"}" } 

as can see , fields string literals , not decoded php array.

try if works.

public function post_follow() {    try {      $user = $this->get_user(input::post('objectid'));      $follow = new parseobject("follow");     $follow->set("from", $this->currentuser);     $follow->set("to", $user);     $follow->save();      $this->output = json_decode($follow->_encode()); // add true in second parameter.  $this->output = json_decode($follow->_encode(), true); } catch(parseexception $ex) {      return $this->error($ex); } 

}


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -