servlet resopnse data for autocomplete
- by shams haque
Hello experts,
Following code is in php. i want to do same in java. Please tell me how do i generate this type of array or collection in java. I need this to response to json autocomplete.
<?php
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array(
"Peter Pan"=>"[email protected]",
"Molly"=>"[email protected]",
"Forneria Marconi"=>"[email protected]",
"Master Sync"=>"[email protected]",
"Dr. Tech de Log"=>"[email protected]",
"Don Corleone"=>"[email protected]",
"Mc Chick"=>"[email protected]",
"Donnie Darko"=>"[email protected]",
"Quake The Net"=>"[email protected]",
"Dr. Write"=>"[email protected]"
);
$result = array();
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
array_push($result, array(
"name" => $key,
"to" => $value
));
}
}
echo json_encode($result);
?>