[ リストオブジェクト複レコード ]
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
// 検索処理 //
ParamExRateSS PE = new ParamExRateSS(vessel);
ArrayList reslist = new ArrayList(PE.selectExRateSSList());
// ++ JSONオブジェクトに格納 ++ //
JSONResultGrid grid = new JSONResultGrid();
grid.setPage(1);
grid.setTotal(1);
grid.setRecords(reslist.size());
grid.setRows(reslist);
//grid.setUserdata(usrdata);
//Gson gson = new Gson(); // 整形なし
Gson gson = new GsonBuilder().setPrettyPrinting().create(); // 整形
String gsonstr = gson.toJson(grid);
// ++ レスポンスを返す ++ //
try {
byte[] res = gsonstr.getBytes("UTF-8"); // <=== UTF-8にしないと文字化けする
response.setContentType(CONTENT_TYPE);
response.setContentLength(res.length);
OutputStream os = response.getOutputStream();
os.write(res);
os.close();
}
catch (Exception e) {
e.printStackTrace();
}
応答文字列
{
"page": 1,
"total": 1,
"records": 1,
"rows": [
{
"id": 182077,
"vessel": "APL CHINA",
"voy": "221W",
"ss": "APL",
"port": "Yokohama",
"dt_atb": "01/01 (Sat)",
"dt_atd": "01/01 (Sat)",
"dt_imp": "11/15 (Thu)",
"rt_imp": 116.65,
"dt_exp": "11/15 (Thu)",
"rt_exp": 116.65,
"tm_add": "12/02 08:28",
"url_link": "http://aplinfo.apl.com/japan/html/daily_schedule.html"
}
]
}