这个php脚本可能是jsp脚本吗?

时间:2014-03-22 14:54:04

标签: java php json jsonp jackson

我想将这个php转换为jsp脚本..因为我不知道php,我不能这样做..请指导我..

PHP从关联数组创建一个JSON对象...但是java没有关联数组,我无法转换它。

$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);

上面的代码是用PHP编写的。我必须转换为PHP ..这是尝试过的代码..

我的代码

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();

是不是?请帮助我

0 个答案:

没有答案