我需要将像这样的查询结果转换为中文:“
将Java中的JSONArray转换成JSON数组。在我的表中,我有以下列:
票据是我自定义的类。 以下是“打印”我的JSON对象的代码:
我需要使用响应(response)。我可以定义一个新的函数来打印。有人能帮我吗?谢谢。
我需要将此类查询结果转换为:
”SELECT * FROM table WHERE column1=X
将Java中的JSONArray转换成JSON数组。在我的表中,我有以下列:
- id:int PRIMARY KEY AUTO_INCREMENT
- string
- string
- string
- string
- string
- int
- timeStamp CURRENT_TIMESTAMP
public static ArrayList<Ticket> lookForATicket(String fermataDiscesa) throws Exception {
Connection dbConn = null;
ArrayList<Ticket> list = null;
try {
try {
dbConn = DBConnection.createConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Statement stmt = dbConn.createStatement();
String query = "SELECT * FROM offer WHERE fermataDiscesa = '" + fermataDiscesa
+ "'";
//test
System.out.println(query);
ResultSet rs = stmt.executeQuery(query);
list = new ArrayList<Ticket>();
Ticket tickets = null;
while (rs.next()) {
//per test
System.out.println(rs.getString(1) + rs.getString(2) + rs.getString(3) + rs.getString(4) + rs.getString(5) + rs.getString(6) + rs.getInt(7));
tickets = new Ticket();
//setto i campi
tickets.setIdGooglePlus(rs.getString("IDGOOGLEPLUS"));
tickets.setIdFacebook(rs.getString("IDFACEBOOK"));
tickets.setFermataSalita(rs.getString("FERMATASALITA"));
tickets.setFermataDiscesa(rs.getString("FERMATADISCESA"));
tickets.setBus(rs.getString("BUS"));
tickets.setTempoRimasto(rs.getInt("TEMPORIMASTO"));
tickets.setTimeStamp(rs.getTimestamp("TIMESTAMP"));
//aggiungo alla lista
list.add(tickets);
}
} catch (SQLException sqle) {
throw sqle;
} catch (Exception e) {
// TODO Auto-generated catch block
if (dbConn != null) {
dbConn.close();
}
throw e;
} finally {
if (dbConn != null) {
dbConn.close();
}
}
return list;
}
票据是我自定义的类。 以下是“打印”我的JSON对象的代码:
//Path: http://localhost:8080/RESTscambio/search
@Path("/search")
public class Search {
// HTTP Get Method
@GET
// Path: http://localhost:8080/RESTscambio/search/dosearch
@Path("/dosearch")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)
public String doSearch(@QueryParam("fermataDiscesa") String fermataDiscesa) throws Exception{
System.out.println("Cerco biglietti..");
ArrayList<Ticket> list = null;
String response = null;
list = DBConnection.lookForATicket(fermataDiscesa);
JSONArray jArray = new JSONArray(list);
if(list != null){
//System.out.println(jObj.put("list_of_ticket", list).toString());
//jObj.put("list_of_ticket", list);
response = Utility.constructJSON("Biglietti disponibili", true);
}else{
response = Utility.constructJSON("Nessun biglietto disponibile", false);
}
return response;
}
我需要使用响应(response)。我可以定义一个新的函数来打印。有人能帮我吗?谢谢。