Hi
I’m pretty new to the whole JSON thing, and I know its more javascript but the problem I’m having is on the php side where I’m generating the JSON code.
The code I have at the moment:
$response["cities"] = array();
while($c = mysql_fetch_array($cities))
{
$response["cities"][$c["cityid"]] = array("id" => (int)$c["cityid"], "name" => $c["name"]);
}
echo json_encode($response);
This works perfectly, but the problem comes when there are no cities (for the selected country.)
If there is a city the output looks as follows:
{"cities": {"44": {"id": 44, "name": "London"} } }
but if there isn’t a city it looks like this:
{"cities": [] }
where as for use on the javascript side I need it to look like this:
{"cities": {} }
How can I get it to do this?
thanks!