Archive for October 2007

Recently, I’ve been doing a lot of work with XML and json. One small problem I ran into was assigning SimpleXML variables to a class variable and then running it through json_encode:

“pageLength”:{”0″:”10″}

The simple solution I came up with, but which were not readily apparent in the documentation is that you need to simply cast the SimpleXML variable to a string or int.

$object->pageLength = (int)$xml->element;

which produces this json:

“pageLength”:0

Hope this helps someone else save some time.