List of usage examples for org.json.simple JSONArray JSONArray
JSONArray
From source file:com.boundlessgeo.geoserver.json.JSONArr.java
public JSONArr() { this(new JSONArray()); }
From source file:mtis.CreateDisplayJson.java
public String getJson(String city, String duration) throws Exception { String finalReturn = ""; JSONArray list = new JSONArray(); JSONObject finalObj = new JSONObject(); ArrayList<String> month = new ArrayList<String>(); month.add("Jan"); month.add("Feb"); month.add("Mar"); month.add("Apr"); month.add("May"); month.add("Jun"); month.add("Jul"); month.add("Aug"); month.add("Sep"); month.add("Oct"); month.add("Nov"); month.add("Dec"); Date d = new Date(); int dayCount = Integer.parseInt(duration); Long dL = d.getTime();/*w w w . j a v a2s . c om*/ FileReader fr = new FileReader( "C:\\Users\\Server\\Documents\\twitterData\\" + city + "\\traffic_data_" + city + "_display.txt"); BufferedReader br = new BufferedReader(fr); String line = br.readLine(); StringBuffer text = new StringBuffer(); while (line != null) { text.append(line); line = br.readLine(); } String textData = text.toString(); textData = textData.replaceAll("\\n", " "); String fullTokens[] = textData.split("\\$\\$\\$"); for (int i = fullTokens.length - 1; i >= 1; i--) { StringTokenizer st = new StringTokenizer(fullTokens[i], "||"); String dateString = st.nextToken(); Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(dateString); Long dateL = date.getTime(); //System.out.println(dateL); String name = st.nextToken(); name = name.replaceAll("'", " "); if (dL - ((dayCount + 1) * 86400 * 1000) <= dateL && dateL <= dL - ((dayCount) * 86400 * 1000)) { //System.out.println("i am in"); JSONObject js = new JSONObject(); js.put("userScreenName", name); System.out.println(name); js.put("userProfilePic", st.nextToken()); js.put("userId", st.nextToken()); js.put("statusId", st.nextToken()); js.put("username", st.nextToken()); js.put("text", st.nextToken()); SimpleDateFormat format = new SimpleDateFormat("hh:mm a "); //System.out.println(format.format(date)); //System.out.println(date.getDate()+"-"+month.get(date.getMonth())+" "+format.format(date)); //System.out.println(dateL); js.put("time", date.getDate() + "-" + month.get(date.getMonth()) + " " + format.format(date)); list.add(js); } line = br.readLine(); } finalObj.put("locations", list); br.close(); finalReturn = finalObj.toString(); System.out.println(finalReturn); return finalReturn; }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static String collectionToJSON(Collection collection) { if (collection == null) { return null; }//from w w w . ja va 2 s. c o m JSONArray array = new JSONArray(); array.addAll(collection); return array.toJSONString(); }
From source file:modelo.UsuariosManagers.Roles.java
public JSONArray getRoles(String usuario, String rol, String codigo) throws SQLException { SeleccionarRoles select = new SeleccionarRoles(); ResultSet rset = select.getRoles(codigo, usuario); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getString("PK_CODIGO")); jsonObject.put("descripcion", rset.getString("VAR_ROL")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }// w w w . j a v a 2 s . c o m select.desconectar(); jsonArreglo.add(jsonArray); return jsonArreglo; }
From source file:JSON.WriteQuestionnaireJSON.java
public void buildJSON(String quesString, String quesid) { JSONObject ques = new JSONObject(); ques.put("name", quesid); ques.put("question", quesString); JSONArray options = new JSONArray(); options.add("High"); options.add("Medium"); options.add("Low"); ques.put("options", options); questions.add(ques);/* w w w . ja va2 s . c o m*/ }
From source file:modelo.ParametrizacionManagers.TipoVisita.java
public JSONArray getTiposVisitas() throws SQLException { //Ejecutamos la consulta y obtenemos el ResultSet SeleccionarTipoVisita select = new SeleccionarTipoVisita(); ResultSet rset = select.getTiposVisitas(); //Creamos los JSONArray para guardar los objetos JSON JSONArray jsonArray = new JSONArray(); JSONArray jsonArreglo = new JSONArray(); //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos //en el JSONArray. while (rset.next()) { //Armamos el objeto JSON con la informacion del registro JSONObject jsonObject = new JSONObject(); jsonObject.put("codigo", rset.getString("CODIGO")); jsonObject.put("descripcion", rset.getString("DESCRIPCION")); //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista. jsonArray.add(jsonObject.clone()); }//from w w w .j a va2 s . c o m jsonArreglo.add(jsonArray); select.desconectar(); return jsonArreglo; }
From source file:com.bigml.histogram.Gap.java
@Override @SuppressWarnings("unchecked") public String toString() { JSONArray jsonArray = new JSONArray(); jsonArray.add(_weight);/*from w w w . ja v a2 s . com*/ jsonArray.add(_startBin); jsonArray.add(_endBin); return jsonArray.toJSONString(); }
From source file:com.aerothai.database.os.OsService.java
public JSONObject GetOsAll() throws Exception { Connection dbConn = null;/* www . ja v a2s . co m*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "list"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM os"; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idos")); jsonData.put("name", rs.getString("name")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } 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 obj; }
From source file:com.aerothai.database.dept.DeptService.java
public JSONObject GetDeptAll() throws Exception { Connection dbConn = null;/*from w ww . ja v a 2 s . c o m*/ JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "list"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM dept"; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("iddept")); jsonData.put("name", rs.getString("name")); jsonData.put("shortname", rs.getString("shortname")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } 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 obj; }
From source file:com.aerothai.database.building.BuildingService.java
public JSONObject GetBuildingAll() throws Exception { Connection dbConn = null;//from w w w . j av a2 s . c o m JSONObject obj = new JSONObject(); JSONArray objList = new JSONArray(); int no = 1; //obj.put("draw", 2); obj.put("tag", "list"); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); String query = "SELECT * FROM building"; System.out.println(query); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { JSONObject jsonData = new JSONObject(); jsonData.put("id", rs.getInt("idbuilding")); jsonData.put("name", rs.getString("name")); jsonData.put("no", no); objList.add(jsonData); no++; } obj.put("msg", "done"); obj.put("status", true); obj.put("data", objList); } 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 obj; }