PDA

View Full Version : json_encode problem



bluetrack
15 Nov 2007, 1:42 AM
Hi!, when i try to add "item1" to the array i can't get the data right with json_encode


$arr = array();
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}

$arr[] = array("item1" => "1");
echo ''.json_encode($arr).''; without item1
[{"id":"39","uName":"Christian"}]

with item1
[{"id":"39","uName":"Christian"},{"item1":"1"}]

how do i do to get the result like this???:
[{"id":"39","uName":"Christian","item1":"1"}]

BernardChhun
15 Nov 2007, 4:07 AM
not Ext related but it's going to be something like this...


$arr = array();
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs)) {
$obj["item1"] = "1";
$arr[] = $obj;
}
echo ''.json_encode($arr).'';