I want to convert this php to jsp script.. since i don't know php , i cant do it.. Please guide me..
The PHP creates a JSON object from associative array... But java have no associatve arrays , i have trouble from converting it.
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
/*
$response->rows[$i]['id']=$row[id];
$response->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
*/
$response->rows[$i]['id']=$row['id'];
$response->rows[$i]['name']=$row['name'];
$response->rows[$i]['author']=$row['author'];
//$response->rows[$i]=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
$i++;
echo json_encode($response);
The above code is in PHP. I have to convert to PHP.. This is the tried code..
My Code
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
public class MapToJSONExample {
ObjectMapper objectMapper = new ObjectMapper();
try {
int i=0;
.....
.....
.....
Map<String, Object> mapObject = new HashMap<String, Object>();
// page,total,records are string var.
mapObject.put("page", page);
mapObject.put("total", total);
mapObject.put("records", records);
List<Object> myList[count] = new ArrayList<Object>();
while (rs.next())
{
myList[i].add(rs.getString("id");
myList[i].add("name");
myList[i].add("author");
mapObject.put("rows", myList[i]);
}
objectMapper.writeValue(out);
} catch (JsonGenerationException e) {
e.printStackTrace();
Is it right ? Pls help me