note 96248 added to function.json-encode
| From: | 5hunter5 at mail dot ru | Date: | Wed, 17 Feb 2010 11:03:02 +0000 |
| Subject: | note 96248 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166050@lists.php.net to get a copy of this message | ||
If I want to encode object whith all it's private and protected properties, then I implements
that methods in my object:
public function encodeJSON()
{
foreach ($this as $key => $value)
{
$json->$key = $value;
}
return json_encode($json);
}
public function decodeJSON($json_str)
{
$json = json_decode($json_str, 1);
foreach ($json as $key => $value)
{
$this->$key = $value;
}
}
Or you may extend your class from base class, wich is implements that methods.
Found that much more simple than regular expressions with PHP serialized objects...
----
Server IP: 69.147.83.197
Probable Submitter: 94.198.34.142
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/96248
Del: integrated -- https://master.php.net/note/delete/96248/integrated
Del: useless -- https://master.php.net/note/delete/96248/useless
Del: bad code -- https://master.php.net/note/delete/96248/bad+code
Del: spam -- https://master.php.net/note/delete/96248/spam
Del: non-english -- https://master.php.net/note/delete/96248/non-english
Del: in docs -- https://master.php.net/note/delete/96248/in+docs
Del: other reasons-- https://master.php.net/note/delete/96248
Reject -- https://master.php.net/note/reject/96248
Search -- https://master.php.net/manage/user-notes.php