List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:mml.handler.post.MMLPostVersionHandler.java
/** * Find the closest matching doialect for the current docid * @return a JSON =Object/*from w ww .ja v a 2s .c o m*/ * @throws DbException */ JSONObject getDialectFromDocid() throws DbException { String res = null; String docID = new String(docid); try { Connection conn = Connector.getConnection(); while (res == null && docID.length() > 0) { res = conn.getFromDb(Database.DIALECTS, docID); if (res == null) docID = Utils.chomp(docID); } if (res == null) res = MMLGetDialectHandler.DEFAULT_DIALECT; else { JSONObject jObj = (JSONObject) JSONValue.parse(res); res = (String) jObj.get(JSONKeys.BODY); } return (JSONObject) JSONValue.parse(res); } catch (DbException e) { throw e; } }
From source file:control.ParametrizacionServlets.InsertarAsociacionContratos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww . j a va2s . 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 { objectErrores = new JSONObject(); arrayErrores = new JSONArray(); //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")); //Creamos el manager y guardamos la informacion. AsociacionContratos manager = new AsociacionContratos(); int error = manager.insertar(contratoPadre, contratoHijo); /* 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); } }
From source file:mediasearch.twitter.TwitterService.java
private ArrayList<TwitterTweet> searchForTweetsAndParseJson(String query) throws UnsupportedEncodingException { final String q = TwitterData.SEARCH_URL + URLEncoder.encode(query, "UTF-8"); HttpsURLConnection connection = bearerAuthConnectionGet(q); if (connection != null) { connection.disconnect();//from www .j a va 2 s. c o m } String readResponse = readResponse(connection); JSONObject obj = (JSONObject) JSONValue.parse(readResponse); return parseJsonIntoTweets(obj); }
From source file:com.olabini.jescov.BranchCoverageStepdefs.java
@Then("^the generated JSON should be:$") public void the_generated_JSON_should_be(String expectedJSON) throws IOException { StringWriter writer = new StringWriter(); new JsonGenerator(writer).generate(data.getCoverageData()); Object expected = JSONValue.parse(expectedJSON); Object real = JSONValue.parse(writer.toString()); assertThat(real, is(expected));/* w w w .j av a2 s . c o m*/ }
From source file:com.appzone.sim.services.handlers.MtLogCheckServiceHandler.java
@Override protected String doProcess(HttpServletRequest request) { String sinceStr = request.getParameter(KEY_SINCE); logger.debug("request mt logs since: {}", sinceStr); long since = Long.parseLong(sinceStr); List<MtMessage> messages = mtMessageRepository.find(since); JSONArray list = new JSONArray(); for (MtMessage mtMessage : messages) { String message = mtMessage.getMessage(); String addresses = JSONValue.toJSONString(mtMessage.getAddresses()); String receivedDate = "" + mtMessage.getReceivedDate(); JSONObject json = new JSONObject(); json.put(JSON_KEY_MESSAGE, message); json.put(JSON_KEY_ADDRESSES, JSONValue.parse(addresses)); json.put(JSON_KEY_RECEIVED_DATE, receivedDate); list.add(json);//from w w w .j ava 2 s . co m } logger.debug("returning response: {}", list); return list.toJSONString(); }
From source file:com.hortonworks.amstore.view.proxy.ResponseTranslator.java
/** * Retrieve response as JSON * @return response as JSON */ public JSONObject asJSON() { String jsonString = asString(); return (JSONObject) JSONValue.parse(jsonString); }
From source file:javarestart.JavaRestartLauncher.java
public static JSONObject getJSON(String url) throws IOException { return (JSONObject) JSONValue.parse(getText(url)); }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static Set<String> JSONToStringSet(String json) { if (json == null || json.isEmpty()) { return null; }/*from w ww .ja v a 2 s.c o m*/ JSONArray parser = (JSONArray) JSONValue.parse(json); if (parser == null) { return null; } Set<String> set = new HashSet<String>(); for (Object obj : parser) { set.add(obj.toString()); } return set; }
From source file:anotadorderelacoes.model.Token.java
/** * Cria um novo token a partir de uma representao no formato JSON * // w w w .j ava 2s . co m * @param tokenJson Representao de um token no formato JSON */ public Token(String tokenJson) { JSONObject json = (JSONObject) JSONValue.parse(tokenJson); token = (String) json.get("t"); lema = (String) json.get("l"); pos = (String) json.get("pos"); sintaxe = (String) json.get("sin"); }
From source file:com.skcraft.launcher.bootstrap.Downloader.java
private void execute() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override/*from w w w . java 2s.co m*/ public void run() { Bootstrap.setSwingLookAndFeel(); dialog = new DownloadFrame(Downloader.this); dialog.setVisible(true); dialog.setDownloader(Downloader.this); } }); File finalFile = new File(bootstrap.getBinariesDir(), System.currentTimeMillis() + ".jar.pack"); File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp"); URL updateUrl = HttpRequest.url(bootstrap.getProperties().getProperty("latestUrl")); log.info("Reading update URL " + updateUrl + "..."); try { String data = HttpRequest.get(updateUrl).execute().expectResponseCode(200).returnContent() .asString("UTF-8"); Object object = JSONValue.parse(data); URL url; if (object instanceof JSONObject) { String rawUrl = String.valueOf(((JSONObject) object).get("url")); if (rawUrl != null) { url = HttpRequest.url(rawUrl.trim()); } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } checkInterrupted(); log.info("Downloading " + url + " to " + tempFile.getAbsolutePath()); httpRequest = HttpRequest.get(url); httpRequest.execute().expectResponseCode(200).saveContent(tempFile); finalFile.delete(); tempFile.renameTo(finalFile); } finally { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dialog.setDownloader(null); dialog.dispose(); } }); } LauncherBinary binary = new LauncherBinary(finalFile); List<LauncherBinary> binaries = new ArrayList<LauncherBinary>(); binaries.add(binary); bootstrap.launchExisting(binaries, false); }