Hi,
When I json_encode result set from $command->queryRow() it stringy all the fields and its hard to distinguish data type of the fields. Specially boolean and int values are stringed.
Here is sample code snippet
$connection = Yii::app()->db;
$command = $connection->createCommand();
$command->select('*)
->from('LISTING l');
->where(array('and', 'l.id=:id'), array(':id' => 1));
$result = $command->queryRow();
return json_encode($result,true);
result set is like this, not the one I expected
{
"id" : "1",
"transmission" : "0",
"doors" : "4",
"title" : "New BMW"
}
In the above code,
id is integer
transmission is boolean and
doors is integer.
Somehow they are strings :-(.
In Yii $command->queryRow() case, I know that it returns object, however json_encode second argument TRUE makes it convert object to associate array though, there is discrepancy in representing the correct format of the data.
I also tried to CJSON::encode() method, no luck, it seems same as json_encode.
This is what I suppose is the correct representation
{
"id" : 1,
"transmission" : 0,
"doors" : 4,
"title" : "New BMW"
}
how do I achieve the above format, provided no manual conversion is applied for each field before json_encode :-).