Мой код PHP:
require ("connect.php");
$input = $_GET["query"];
$data = array();
$query = mysql_query("SELECT `abbr` FROM `states_list` WHERE `abbr` LIKE '{$input}%'") or die(mysql_error());
while ($obj = mysql_fetch_object($query)) {
//$json = array();
//$json['query'] = $input;
//$json['suggestion'] = $row['abbr'];
$json[] = $obj;
$data = array("query"=>"$input", "suggestion"=>array($obj));
}
header("Content-type: application/json");
//echo json_encode($data);
echo '{"query":'.$input.' "suggestion":'.json_encode($json).'}';
Это мой фактический ответ:
{"query":c "suggestion":[{"abbr":"CA"},{"abbr":"CO"},{"abbr":"CT"}]}
Вот как бы я хотел, чтобы это выглядело:
{"query":c "suggestion":["CA","CO","CT"]}
Не могу понять, как правильно организовать вывод, чтобы получить то, что я хочу; (