Hi all,
I used the Zend_Json class to json encode an array of object.
I notified that Zend_Json::encode call a method 'toJson' if it present in my
object, so i implemented it.
But when I tried to json encode an array of my object, the Zend_Json_Encoder
doesn't call this method.
Here an example:
$var1 = new MyCustomClass();
$var2 = array(new MyCustomClass(), new MyCustomClass());
Zend_Json::encode($var1); // call toJson() method of the object
"{"test":"cool"}"
Zend_Json::encode($var2); // dont call toJson() method "[{},{}]"
If it's a normal way, why the Zend_Json_Encoder doesn't try to call 'toJson'
method on my object ?
To fix my problem fastly, i'll extend Zend_Json_Encoder class to modify
_encodeObject mehod, but i'm looking for a better solution.
Any idea ? Cheers
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-Json-Encoder-strange-behaviour-with-array-of-Object-tp3444195p3444195.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]