List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:control.ParametrizacionServlets.ActualizarPuntoVertimiento.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww. jav a 2 s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject resError = new JSONObject(); try { //Obtenemos el numero de contrato Double contrato = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("puntos"); Object obj = JSONValue.parse(puntos); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); String ubicacion = (String) jsonObject.get("ubicacion"); String latitud = (String) jsonObject.get("latitud"); String longitud = (String) jsonObject.get("longitud"); String observacion = (String) jsonObject.get("observacion"); int estado = Integer.parseInt((String) jsonObject.get("estado")); String codigo = (String) jsonObject.get("codigo"); String tipoEstructura = (String) jsonObject.get("tipoEstructura"); //Creamos el manager y guardamos la informacion. PuntosVertimiento manager = new PuntosVertimiento(); manager.actualizar(codigo, ubicacion, latitud, longitud, observacion, estado, contrato, tipoEstructura); } resError.put("error", 1); } catch (Exception ex) { resError.put("error", 0); } }
From source file:bolt.DucksBoardMap.java
public DucksBoardMap(String json) { Object obj = JSONValue.parse(json); JSONArray array = (JSONArray) obj;/*w w w.j ava2 s . com*/ JSONObject obj2 = (JSONObject) array.get(0); this.idString = obj2.get("id").toString(); this.keyString = obj2.get("key").toString(); JSONArray fieldsJson = (JSONArray) obj2.get("requiredFields"); String[] fieldsTmp = new String[fieldsJson.size()]; //if (fieldsJson.size() == 0) for (int i = 0; i < fieldsJson.size(); i++) { fieldsTmp[i] = (String) fieldsJson.get(i); } this.fields = fieldsTmp; }
From source file:importer.handler.post.stages.StageThreeText.java
/** * Set the text-specific config for the text filter * @param config a json document from the database *//*from ww w .j ava2 s .c o m*/ public void setConfig(String config) { this.config = (JSONObject) JSONValue.parse(config); }
From source file:com.bradleyjh.blazefly.Updater.java
public void run() { URL url;/*w w w .ja v a2s . co m*/ try { url = new URL("https://api.curseforge.com/servermods/files?projectIds=50224"); } catch (MalformedURLException e) { return; } try { URLConnection conn = url.openConnection(); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String response = reader.readLine(); JSONArray array = (JSONArray) JSONValue.parse(response); if (array.size() > 0) { JSONObject latest = (JSONObject) array.get(array.size() - 1); String latestFile = (String) latest.get("name"); // SomePlugin v2.3 = "230", SomePlugin v2.3.4 = "234" // means we can check if the newer file is a newer version String latestVersion = latestFile.replaceAll("\\D+", ""); if (latestVersion.length() == 2) { latestVersion = latestVersion + "0"; } thisVersion = thisVersion.replaceAll("\\D+", ""); if (thisVersion.length() == 2) { thisVersion = thisVersion + "0"; } if (Integer.parseInt(latestVersion) > Integer.parseInt(thisVersion)) { main.updateAvailable = latestFile; main.getLogger().info(latestFile + " is available for download!"); } } } catch (IOException e) { return; } }
From source file:com.turt2live.uuid.turt2live.v2.ApiV2Service.java
@Override protected PlayerRecord parsePlayerRecord(String json) { if (json == null) return null; JSONObject jsonValue = (JSONObject) JSONValue.parse(json); if (jsonValue.containsKey("uuid") && jsonValue.containsKey("name") && jsonValue.containsKey("offline-uuid") && jsonValue.containsKey("expires-in") && jsonValue.containsKey("expires-on")) { String uuidStr = (String) jsonValue.get("uuid"); String name = (String) jsonValue.get("name"); String offlineStr = (String) jsonValue.get("offline-uuid"); Object expiresOn = jsonValue.get("expires-on"); Object expiresIn = jsonValue.get("expires-in"); boolean cached = jsonValue.containsKey("source") && ((String) jsonValue.get("source")).equalsIgnoreCase("cache"); if (name.equals("unknown") || uuidStr.equals("unknown")) return null; if (expiresOn == null) expiresOn = "0"; if (expiresIn == null) expiresIn = "0"; long expOn, expIn; try {/*from w w w. j a va2s . co m*/ if (expiresOn instanceof String) expOn = Long.parseLong((String) expiresOn); else expOn = (Long) expiresOn; expOn *= 1000; // Milliseconds if (expiresIn instanceof String) expIn = Long.parseLong((String) expiresIn); else expIn = (Long) expiresIn; } catch (Exception ignored) { return null; // Connection problem or other issue } UUID uuid = UUID.fromString(uuidStr); UUID offlineUuid = UUID.fromString(offlineStr); return new Turt2LivePlayerRecord(uuid, name, offlineUuid, expIn, expOn, cached); } return null; }
From source file:mml.handler.get.MMLResourceHandler.java
String getDefaultResource(String urn) throws DbException { Connection conn = Connector.getConnection(); String original = new String(urn); String jStr = null;// w ww. j a va 2 s .c o m do { jStr = conn.getFromDb(database, urn); if (jStr == null) { if (this.database.equals(Database.CORFORM)) { jStr = conn.getFromDb(database, urn + "/default"); if (jStr == null) urn = Utils.chomp(urn); else break; } else break; } } while (jStr == null); if (jStr == null) throw new DbException("Failed to find " + original); String bodyStr = ""; if (jStr != null) { JSONObject jDoc = (JSONObject) JSONValue.parse(jStr); bodyStr = (String) jDoc.get(JSONKeys.BODY); } else throw new DbException("body key not found"); return bodyStr; }
From source file:bolt.DucksBoardTimeline.java
public DucksBoardTimeline(String json) { Object obj = JSONValue.parse(json); JSONArray array = (JSONArray) obj;/*from ww w .ja v a2 s.co m*/ JSONObject obj2 = (JSONObject) array.get(0); this.idString = obj2.get("id").toString(); this.keyString = obj2.get("key").toString(); JSONArray fieldsJson = (JSONArray) obj2.get("requiredFields"); String[] fieldsTmp = new String[fieldsJson.size()]; //if (fieldsJson.size() == 0) for (int i = 0; i < fieldsJson.size(); i++) { fieldsTmp[i] = (String) fieldsJson.get(i); } this.fields = fieldsTmp; }
From source file:ci6226.eval_index_writer.java
public eval_index_writer(Analyzer _analyzer, String _iReviewLocation, String _dir) throws IOException { String file = _iReviewLocation; JSONParser parser = new JSONParser(); BufferedReader in = new BufferedReader(new FileReader(file)); Date start = new Date(); String indexPath = "./" + _dir; System.out.println("Indexing to directory '" + indexPath + "'..."); Analyzer analyzer = _analyzer;/* w w w . j a v a 2 s. c om*/ IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer); Directory dir = FSDirectory.open(new File(indexPath)); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); IndexWriter writer = new IndexWriter(dir, iwc); // int line=0; while (in.ready()) { String s = in.readLine(); Object obj = JSONValue.parse(s); JSONObject person = (JSONObject) obj; String text = (String) person.get("text"); String user_id = (String) person.get("user_id"); String business_id = (String) person.get("business_id"); String review_id = (String) person.get("review_id"); JSONObject votes = (JSONObject) person.get("votes"); long funny = (Long) votes.get("funny"); long cool = (Long) votes.get("cool"); long useful = (Long) votes.get("useful"); Document doc = new Document(); Field review_idf = new StringField("review_id", review_id, Field.Store.YES); doc.add(review_idf); // Field business_idf = new StringField("business_id", business_id, Field.Store.YES); // doc.add(business_idf); //http://qindongliang1922.iteye.com/blog/2030639 FieldType ft = new FieldType(); ft.setIndexed(true);// ft.setStored(true);// ft.setStoreTermVectors(true); ft.setTokenized(true); ft.setStoreTermVectorPositions(true);// ft.setStoreTermVectorOffsets(true);// Field textf = new Field("text", text, ft); doc.add(textf); // Field user_idf = new StringField("user_id", user_id, Field.Store.YES); // doc.add(user_idf); // doc.add(new LongField("cool", cool, Field.Store.YES)); // doc.add(new LongField("funny", funny, Field.Store.YES)); // doc.add(new LongField("useful", useful, Field.Store.YES)); writer.addDocument(doc); // System.out.println(line++); } writer.close(); Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); }
From source file:control.ProcesoVertimientosServlets.RegistrarSuperviciones.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//ww w.j ava 2 s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONArray resp = new JSONArray(); try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String monitoreos = request.getParameter("monitoreos"); int tecnico = Integer.parseInt(request.getParameter("tecnico")); int resul; int codProceso; JSONObject jsonObject = new JSONObject(); JSONArray jsonArray = new JSONArray(); Object obj = JSONValue.parse(monitoreos); JSONArray monitoreosArray = new JSONArray(); monitoreosArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < monitoreosArray.size(); i++) { codProceso = Integer.parseInt(monitoreosArray.get(i).toString()); ProgramarMonitoreo manager = new ProgramarMonitoreo(); resul = manager.registrarSupervision(codProceso, tecnico); jsonObject.put("monitoreo", codProceso); jsonObject.put("resultado", resul); jsonArray.add(jsonObject.clone()); } resp.add(jsonArray); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); for (Object jsonObjectResp : resp) { response.getWriter().write(jsonObjectResp.toString()); } } catch (Exception ex) { } }
From source file:control.ParametrizacionServlets.ActualizarAsociacionContratos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w. ja v a2s .c om * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //Obtenemos el numero de contrato Double contratoPadre = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("contratosAsignados"); Object obj = JSONValue.parse(puntos); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { //Obtenemos el contrato hijo JSONObject jsonObject = (JSONObject) jsonArray.get(i); Double contratoHijo = Double.parseDouble((String) jsonObject.get("contratoAsignado")); String codigo = (String) jsonObject.get("codigo"); //Creamos el manager y guardamos la informacion. AsociacionContratos manager = new AsociacionContratos(); int error = manager.actualizar(contratoPadre, contratoHijo, codigo); /* Obtenemos la respuesta del procedimiento y Validamos si el contrato padre es valido, si no lo es no registramos nada y enviamos el error. */ if (error == 2) { guardarErrores(error, contratoPadre); escribirJSON(response); break; } else if (error == 4) { //Si el hijo no es valido, registramos el error y //enviamos el listado a la vista al finalizar el for. guardarErrores(error, contratoHijo); } } escribirJSON(response); } catch (Exception ex) { JSONObject respError = new JSONObject(); respError.put("error", 0); arrayErrores.add(respError); escribirJSON(response); } }