I have a CFResponse, which I would like to parse into an array like this:
$response = $this->scan($query);
$array = $response->body->Items->to_array();
print_r($array);
This gives me an empty CFArray, for some reason, while
$response->body->Items->to_json();
other hand gives me this:
{"userID":{"S":"someemail@me.com"},"password":{"S":"secretPassword"}}
which is only the first row.
However, this is what I get through $response->body;
CFSimpleXML Object ( [ConsumedCapacityUnits] => 0.5 [Count] => 2 [Items] => Array ( [0] => CFSimpleXML Object ( [userID] => CFSimpleXML Object ( [S] => someemail@me.com ) [password] => CFSimpleXML Object ( [S] => secretPassword ) ) [1] => CFSimpleXML Object ( [userID] => CFSimpleXML Object ( [S] => somemoreemail@me.com ) [password] => CFSimpleXML Object ( [S] => secretPassword ) ) ) [ScannedCount] => 2 )
As you can see here, Items is an array. It’s a SimpleXMLIterator object.
There are two rows being returned.
By calling Items, I only get the first object. How can I parse all children into an array, or at least make a json string? I’ve tried getChildren(), which didn’t work.
Also, why isn’t to_array() working?
1 Answer