List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:com.p000ison.dev.copybooks.util.Helper.java
public static ArrayList<String> fromJSONStringtoList(String key, String string) { if (string != null && !string.isEmpty()) { ArrayList<String> out = new ArrayList<String>(); JSONObject flags = (JSONObject) JSONValue.parse(string); if (flags != null) { for (Object keys : flags.keySet()) { try { if (keys.equals(key)) { JSONArray list = (JSONArray) flags.get(keys); if (list != null) { for (Object k : list) { out.add(k.toString()); }/*from www . j a va 2s . co m*/ } } } catch (Exception ex) { CopyBooks.debug(String.format("Failed reading flag: %s", keys)); CopyBooks.debug(String.format("Value: %s", flags.get(key))); CopyBooks.debug(null, ex); } } } return out; } return null; }
From source file:me.neatmonster.spacertk.PanelListener.java
/** * Interprets a raw command from the panel (multiple) * @param string input from panel//from w ww . j a v a2 s . c om * @return result of the action * @throws InvalidArgumentsException Thrown when the wrong arguments are used by the panel * @throws UnhandledActionException Thrown when there is no handler for the action */ @SuppressWarnings("unchecked") private static Object interpretm(final String string) throws InvalidArgumentsException, UnhandledActionException { final int indexOfMethod = string.indexOf("?method="); final int indexOfArguments = string.indexOf("&args="); final int indexOfKey = string.indexOf("&key="); final String methodString = string.substring(indexOfMethod + 8, indexOfArguments); final String argumentsString = string.substring(indexOfArguments + 6, indexOfKey); final List<Object> methods = (List<Object>) JSONValue.parse(methodString); final List<Object> arguments = (List<Object>) JSONValue.parse(argumentsString); final List<Object> result = (List<Object>) JSONValue.parse("[]"); for (int i = 0; i < methods.size(); i++) { String argsString = arguments.toArray()[i].toString(); List<Object> args = (List<Object>) JSONValue.parse(argsString); try { if (SpaceRTK.getInstance().actionsManager.contains(methods.toArray()[i].toString())) result.add(SpaceRTK.getInstance().actionsManager.execute(methods.toArray()[i].toString(), args.toArray())); } catch (final InvalidArgumentsException e) { result.add(null); e.printStackTrace(); } catch (final UnhandledActionException e) { result.add(null); e.printStackTrace(); } } return result; }
From source file:com.anhth12.spark.kafka.consumer.ZkState.java
public Map<Object, Object> readJSON(String path) { try {/* w ww .ja v a 2s. c o m*/ byte[] b = readByte(path); if (b == null) { return null; } return (Map<Object, Object>) JSONValue.parse(new String(b, "UTF-8")); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:mml.handler.scratch.ScratchVersionSet.java
private void parseResource(String resource) { JSONObject jObj = (JSONObject) JSONValue.parse(resource); this.otherFields = new HashMap<String, Object>(); Set<String> keys = jObj.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); if (key.equals(JSONKeys._ID)) continue; else if (key.equals(JSONKeys.DOCID)) docid = (String) jObj.get(JSONKeys.DOCID); else if (key.equals(JSONKeys.BODY)) body = (String) jObj.get(JSONKeys.BODY); else if (key.equals(JSONKeys.VERSION1)) version1 = (String) jObj.get(JSONKeys.VERSION1); else if (key.equals(JSONKeys.FORMAT)) format = (String) jObj.get(JSONKeys.FORMAT); else//from ww w . j a v a2 s . c o m otherFields.put(key, jObj.get(key)); } }
From source file:control.ParametrizacionServlets.ActualizarLaboratorios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w.j a va 2s . 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 { JSONObject salida = new JSONObject(); try { String nombre = request.getParameter("nombre"); String direccion = request.getParameter("direccion"); String telefono = request.getParameter("telefono1"); String telefono2 = request.getParameter("telefono2"); String correo = request.getParameter("correo"); String resolucion = request.getParameter("resolucion"); String vigencia = request.getParameter("vigencia"); String contactos = request.getParameter("contactos"); Integer codigo = Integer.parseInt(request.getParameter("codigo")); String paramAcreditados = request.getParameter("paramAcreditados"); Laboratorios manager = new Laboratorios(); manager.actualizar(nombre, contactos, direccion, telefono, telefono2, correo, resolucion, vigencia, codigo); int resp = 0; //Obtenemos La informacion del manager AcreditacionParametros managerAcreditacion = new AcreditacionParametros(); //Eliminamos lo parametros resp = managerAcreditacion.eliminar(codigo); Object obj = JSONValue.parse(paramAcreditados); 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); int codParametro = Integer.parseInt((String) jsonObject.get("codigoParam")); managerAcreditacion.insertar(codParametro, codigo); } } catch (Exception e) { } }
From source file:muscle.core.CxADescription.java
private CxADescription() { tmpDir = JVM.ONLY.tmpDir();/*from ww w.ja v a 2s.c o m*/ logger.log(Level.INFO, "Using directory <{0}>", tmpDir); description = new HashMap<String, Object>(); final String envFilename = System.getProperty(ENV_PROPERTY); if (envFilename == null) { logger.severe("Property muscle.Env is not specified; cannot start MUSCLE"); System.exit(1); } else { try { final File envFile = new File(envFilename); Reader reader = new BufferedReader(new FileReader(envFile)); // treat input as a org.json.simple.JSONObject and put in our env @SuppressWarnings("unchecked") Map<String, Object> jsonHash = (Map<String, Object>) JSONValue.parse(reader); @SuppressWarnings("unchecked") Map<String, Object> cxaParams = (Map<String, Object>) jsonHash.get(CXA_KEY); if (cxaParams == null) { logger.severe("CxA parameters are not passed in the configuration."); System.exit(1); } // load (mandatory) cxa properties from muscle environment description.putAll(cxaParams); } catch (FileNotFoundException e) { logger.log(Level.SEVERE, "Cannot load MUSCLE parameters from <" + envFilename + ">: path does not exist", e); System.exit(1); } } }
From source file:com.memetix.gun4j.GunshortenAPI.java
private static JSONObject parseJSON(final String jsonResponse) throws ParseException { return (JSONObject) JSONValue.parse(jsonResponse); }
From source file:mml.handler.post.MMLPostVersionHandler.java
/** * Handle a POST request/*from w w w. ja v a2 s.c om*/ * @param request the raw request * @param response the response we will write to * @param urn the rest of the URL after stripping off the context * @throws MMLException */ public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws MMLException { try { String value = request.getParameter("data"); if (value != null) { JSONObject jObj = (JSONObject) JSONValue.parse(value); this.version1 = (String) jObj.get(JSONKeys.VERSION1); if (version1 == null) version1 = "/base"; else version1 = URLDecoder.decode(version1, "UTF-8"); this.longName = (String) jObj.get(JSONKeys.LONGNAME); this.docid = (String) jObj.get(JSONKeys.DOCID); this.dialect = getDialectFromDocid(); JSONArray layers = (JSONArray) jObj.get("layers"); ScratchVersion corcodeDefault = new ScratchVersion(version1, longName, docid + "/default", Database.CORCODE, null, true); ScratchVersion corcodePages = new ScratchVersion(version1, longName, docid + "/pages", Database.CORCODE, null, true); ScratchVersion text = new ScratchVersion(version1, longName, docid, Database.CORTEX, null, true); this.style = ScratchVersionSet.getDefaultStyleName(docid); for (int i = 0; i < layers.size(); i++) { JSONObject layer = (JSONObject) layers.get(i); String name = (String) layer.get(JSONKeys.NAME); String html = (String) layer.get(JSONKeys.BODY); stil = new STILDocument(style); pages = new STILDocument(style); // reduce html to text, corcode-default and corcode-pages Document doc = Jsoup.parseBodyFragment(html); Element body = doc.body(); parseBody(body); int num = ScratchVersion.layerNumber(name); text.addLayer(sb.toString().toCharArray(), num); corcodeDefault.addLayer(stil.toString().toCharArray(), num); corcodePages.addLayer(pages.toString().toCharArray(), num); } Scratch.save(text); Scratch.save(corcodeDefault); Scratch.save(corcodePages); response.setContentType("text/plain"); response.getWriter().write("OK"); } } catch (Exception e) { System.out.println(e.getMessage()); throw new MMLException(e); } }
From source file:compare.handler.get.MetadataHandler.java
/** * Get the version1 metadata item from the CORTEX BSON * @param conn the database connection/*from www . ja v a2 s.c o m*/ * @throws CompareException if the database fetch failed */ public void getMetadataFromCortex(Connection conn) throws CompareException { try { String res = conn.getFromDb(Database.CORTEX, docid); JSONObject jObj2 = (JSONObject) JSONValue.parse(res); if (jObj2.containsKey(metadataKey)) metadataValue = (String) jObj2.get(metadataKey); else getMetadataFromObject(jObj2); } catch (Exception e) { throw new CompareException(e); } }
From source file:bhl.pages.handler.PagesDocumentsHandler.java
/** * Get a pukka title from the options collection * @param docid the docid to get the title from * @return the pukka title or null/*from w w w . j a v a2s . c o m*/ */ String getPukkaTitle(Connection conn, String docid) { try { String jstr = conn.getFromDbByField(Database.OPTIONS, docid, JSONKeys.DOCID); JSONObject jobj = (JSONObject) JSONValue.parse(jstr); return (String) jobj.get(JSONKeys.TITLE); } catch (DbException dbe) { return null; } }