List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:bhl.pages.handler.PagesListHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MissingDocumentException { try {//from w w w .j a va2s . co m String docid = request.getParameter(Params.DOCID); if (docid != null) { Connection conn = Connector.getConnection(); String[] keys = new String[2]; keys[0] = JSONKeys.BHL_PAGE_ID; keys[1] = JSONKeys.PAGE_SEQUENCE; String[] pages = conn.listCollectionBySubKey(Database.PAGES, JSONKeys.IA_IDENTIFIER, docid, keys); JSONArray list = new JSONArray(); for (int i = 0; i < pages.length; i++) { JSONObject jobj = (JSONObject) JSONValue.parse(pages[i]); Number pageNo = (Number) jobj.get(JSONKeys.PAGE_SEQUENCE); Number pageId = (Number) jobj.get(JSONKeys.BHL_PAGE_ID); System.out.println("pageNo=" + pageNo + " pageId=" + pageId); PageDesc ps = new PageDesc(new Integer(pageNo.intValue()).toString(), new Integer(pageId.intValue()).toString()); list.add(ps.toJSONObject()); } PagesGetHandler.sortList(list); response.setContentType("application/json"); response.getWriter().print(list.toJSONString()); } else throw new Exception("Must specify document identifier"); } catch (Exception e) { throw new MissingDocumentException(e); } }
From source file:control.ProcesoVertimientosServlets.InsertarVerificacionInfoCaracterizacion.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// www .j a v a2s . 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 { try { //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String respuestas = request.getParameter("respuestas"); Integer codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); Object obj = JSONValue.parse(respuestas); 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 checkeado = (String) jsonObject.get("checkeado"); Integer codigo = Integer.parseInt((String) jsonObject.get("codigo")); //Creamos el manager y guardamos la informacion. VerificacionInfoCaracterizacion manager = new VerificacionInfoCaracterizacion(); manager.insertar(checkeado, codigo, codigoProceso); } } catch (Exception ex) { //Logger.getLogger(InsertarActEconomica.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:control.ParametrizacionServlets.InsertarPuntoVertimientoContrato.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// www . j a va 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 { 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"); String tipoEstructura = (String) jsonObject.get("tipoEstructura"); int estado = Integer.parseInt((String) jsonObject.get("estado")); //Creamos el manager y guardamos la informacion. PuntosVertimiento manager = new PuntosVertimiento(); manager.insertar(ubicacion, latitud, longitud, observacion, estado, contrato, tipoEstructura); } } catch (Exception ex) { //Logger.getLogger(InsertarActEconomica.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:control.ProcesoVertimientosServlets.RegistrarTasaRetibutiva.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w. j av 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 { int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); String cargasParam = request.getParameter("cargasParam"); String valorTasaCobrada = request.getParameter("valorTasaCobrada"); String valorTotalTasaPagar = request.getParameter("valorTotalTasaPagar"); Object obj = JSONValue.parse(cargasParam); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; for (int i = 0; i < jsonArray.size(); i++) { //Obtenemos los valores por parametro JSONObject jsonObject = (JSONObject) jsonArray.get(i); String valorTarifa = (String) jsonObject.get("valorTarifa"); String procentajeRemocion = (String) jsonObject.get("procentajeRemocion"); String valorTasa = (String) jsonObject.get("valorTasa"); String valorCarga = (String) jsonObject.get("valorCarga"); String codigoParametro = (String) jsonObject.get("codigoParametro"); try { //Creamos el manager y guardamos la informacion. ProgramarMonitoreo manager = new ProgramarMonitoreo(); manager.registrarTasaRetributiva(codigoProceso, Integer.parseInt(codigoParametro), valorTarifa, procentajeRemocion, valorTasa, valorCarga, valorTasaCobrada, valorTotalTasaPagar); } catch (Exception ex) { } } String codigoParametro = ""; String valorTarifa = request.getParameter("codigoProceso"); String procentajeRemocion = request.getParameter("codigoProceso"); String valorTasa = request.getParameter("codigoProceso"); String valorCarga = request.getParameter("codigoProceso"); }
From source file:cz.mgn.mediservice.rest.Loader.java
protected static Object parse(String source) { return JSONValue.parse(source); }
From source file:me.neatmonster.spacertk.scheduler.Scheduler.java
/** * Loads all the saved jobs from the file *//*from ww w . j a v a2 s. c om*/ public static void loadJobs() { if (!JOBS_FILE.exists()) try { JOBS_FILE.createNewFile(); } catch (final IOException e) { e.printStackTrace(); } final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(JOBS_FILE); final LinkedList<String> jobsNames = new LinkedList<String>(); for (final String key : configuration.getKeys(false)) if (key.contains(".")) jobsNames.add(key.split("\\.")[0]); for (final String jobName : jobsNames) if (!jobs.containsKey(jobName)) { final String timeType = configuration.getString(jobName + ".TimeType"); final String timeArgument = configuration.getString(jobName + ".TimeArgument"); final String actionName = configuration.getString(jobName + ".ActionName"); @SuppressWarnings("unchecked") final Object[] actionArguments = ((List<Object>) JSONValue .parse((String) configuration.get(jobName + ".ActionArguments"))).toArray(); try { final Job job = new Job(actionName, actionArguments, timeType, timeArgument, true); jobs.put(jobName, job); } catch (final UnSchedulableException e) { e.printStackTrace(); } catch (final UnhandledActionException e) { e.printStackTrace(); } } try { configuration.save(JOBS_FILE); } catch (IOException e) { e.printStackTrace(); } }
From source file:mml.handler.get.MMLMetadataHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try {//from ww w. j a v a 2 s . c o m Connection conn = Connector.getConnection(); docid = request.getParameter(Params.DOCID); if (docid == null || docid.length() == 0) docid = urn; JSONObject md = new JSONObject(); boolean changed = false; String docId = docid; do { String jStr = conn.getMetadata(docId); if (jStr != null) { JSONObject jObj = (JSONObject) JSONValue.parse(jStr); Set<String> keys = jObj.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); md.put(key, jObj.get(key)); } changed = true; } else { String ctStr = conn.getFromDb(Database.CORTEX, docId); if (ctStr != null) { JSONObject jObj = (JSONObject) JSONValue.parse(ctStr); if (jObj.containsKey(JSONKeys.DESCRIPTION)) { String desc = ((String) jObj.get(JSONKeys.DESCRIPTION)).replaceAll("%20", " "); if (desc.startsWith("\"")) desc = desc.substring(1); if (desc.endsWith("\"")) desc = desc.substring(0, desc.length() - 2); desc = desc.replaceAll("\"\"", "\""); md.put(JSONKeys.TITLE, desc); } else if (!md.containsKey(JSONKeys.TITLE) && DocType.isLetter(docId)) { int index = docId.lastIndexOf("/"); String shortId; if (index != -1) shortId = docId.substring(index + 1); else shortId = docId; String[] parts = shortId.split("-"); StringBuilder sb = new StringBuilder(); String projid = Utils.getProjectId(docId); if (parts.length >= 2) { String from = Acronym.expand(projid, parts[parts.length - 2]); String to = Acronym.expand(projid, parts[parts.length - 1]); sb.append("Letter from " + from); sb.append(" to "); sb.append(to); sb.append(","); } if (parts.length >= 3) { for (int i = 0; i < 3; i++) { if (DocType.isDay(parts[i])) { sb.append(" "); sb.append(trimZeros(parts[i])); } else if (DocType.isMonth(parts[i])) { sb.append(" "); sb.append(Acronym.expand(projid, parts[i])); } else if (DocType.isYear(parts[i])) { sb.append(" "); sb.append(parts[i]); // maybe only a year break; } } md.put(JSONKeys.TITLE, sb.toString()); } } else System.out.println("No metadata found for " + docId); } else System.out.println("No metadata found for " + docId); changed = false; } docId = Utils.chomp(docId); } while (changed); response.setContentType("application/json"); response.setCharacterEncoding(encoding); String mdStr = md.toJSONString(); response.getWriter().println(mdStr); } catch (Exception e) { throw new MMLException(e); } }
From source file:com.rmtheis.yandtran.YandexTranslatorAPI.java
/** * Forms a request, sends it using the GET method and returns the value with the given label from the * resulting JSON response.// w w w. j ava 2 s . c o m */ protected static String retrievePropString(final URL url, final String jsonValProperty) throws Exception { final String response = retrieveResponse(url); JSONObject jsonObj = (JSONObject) JSONValue.parse(response); return jsonObj.get(jsonValProperty).toString(); }
From source file:javarestart.Utils.java
public static JSONObject getJSON(final URL url) throws IOException { return (JSONObject) JSONValue.parse(getText(url)); }
From source file:com.storageroomapp.client.AccountInfo.java
/** * Parses a String of json text and returns an AccountInfo object. * It will correctly parse the AccountInfo object if it is toplevel, * or also if nested in an 'account' key-value pair. * /*from w ww. j a v a 2 s.c o m*/ * @param json the String with the json text * @return an AccountInfo object, or null if the parsing failed */ static public AccountInfo parseJson(String json) { JSONObject root = (JSONObject) JSONValue.parse(json); if (root == null) { return null; } JSONObject account = (JSONObject) root.get("account"); if (account == null) { return null; } return parseJsonObject(account); }