List of usage examples for org.json.simple JSONValue parse
public static Object parse(String s)
From source file:com.turt2live.uuid.turt2live.v1.ApiV1Service.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")) { String uuidStr = (String) jsonValue.get("uuid"); String name = (String) jsonValue.get("name"); if (name.equals("unknown") || uuidStr.equals("unknown")) return null; UUID uuid = convertUuid(uuidStr); return new Turt2LivePlayerRecord(uuid, name); }// w w w . jav a 2 s . c o m return null; }
From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java
public static Map<String, Double> getNodesOfInterest(File f) throws FileNotFoundException { FileReader rd = new FileReader(f); BufferedReader br = new BufferedReader(rd); JSONArray arr = (JSONArray) JSONValue.parse(br); return getNodesOfInterest(arr); }
From source file:com.jgoetsch.eventtrader.source.ApeStreamingMsgSource.java
public void receiveMsgs(HttpClient client) { if (executeRequest(client, createCommandRequest("CONNECT", getRequestParameters()), new MsgParser() { public boolean parseContent(InputStream input, long length, String contentType, MsgHandler handler) { JSONArray responseJson = (JSONArray) JSONValue .parse(new BufferedReader(new InputStreamReader(input))); for (Object obj : responseJson) { if (((JSONObject) obj).get("raw").equals("LOGIN")) { JSONObject data = (JSONObject) ((JSONObject) obj).get("data"); sessid = (String) data.get("sessid"); }/* ww w . j a v a2 s. co m*/ } if (sessid != null) return true; else { log.error("Could not find sessid in server response: " + responseJson.toString()); return false; } } })) { log.info("Connected to " + getUrl() + " with session id " + sessid); if (initialCommands != null) { for (Command command : initialCommands) { log.info("Issuing command " + command.getCmd() + " " + command.getParams()); if (!executeRequest(client, createCommandRequest(command.getCmd(), command.getParams()), getMsgParser())) break; } } super.receiveMsgs(client); } }
From source file:muscle.core.conduit.terminal.JSONSource.java
@Override /**/*from ww w.j a v a2 s .c om*/ * Get the JSON HashMap from the given URL. * The keys of the hashmap are keys, the objects should be tested for their * datatype, which can be Boolean, Long, String, HashMap or Double, ArrayList or null. */ protected Observation<HashMap<String, Object>> generate() throws InterruptedException { BufferedReader in = null; Observation<HashMap<String, Object>> obs = null; try { in = new BufferedReader(new InputStreamReader(url.openStream())); JSONObject jsonHash = (JSONObject) JSONValue.parse(in); // Will only work if the keys of the JSON object are strings, which // they always are. @SuppressWarnings("unchecked") HashMap<String, Object> map = new HashMap<String, Object>(jsonHash); // Each iteration simply takes the old timestamp and a new timestamp obs = new Observation<HashMap<String, Object>>(map, new Timestamp(iteration), new Timestamp(++iteration)); } catch (IOException ex) { Logger.getLogger(JSONSource.class.getName()).log(Level.SEVERE, "Can not connect to URL <" + url + "> with JSON source.", ex); } finally { try { if (in != null) in.close(); } catch (IOException ex) { } } return obs; }
From source file:formatter.handler.get.Version1Handler.java
/** * Get the version1 metadata item from the CORTEX BSON * @param conn the database connection// ww w . ja v a2 s. com * @throws CompareException if the database fetch failed */ void getMetadataFromCortex(Connection conn) throws FormatterException { try { String res = conn.getFromDb(Database.CORTEX, docid); JSONObject jObj2 = (JSONObject) JSONValue.parse(res); if (jObj2.containsKey(JSONKeys.VERSION1)) metadataValue = (String) jObj2.get(JSONKeys.VERSION1); else getMetadataFromObject(jObj2); } catch (Exception e) { throw new FormatterException(e); } }
From source file:com.punyal.blackhole.tentacle.Tentacle.java
@Override public void run() { // Valid Ticket CoapResponse response;//from ww w .j a va 2 s . c o m String uri, encoded; while (true) { if (myTicket.getExpireTime() < System.currentTimeMillis()) { // Ask for an authenticator uri = "coap://waffle.punyal.com:5682/Authentication"; coapClient.setURI(uri); response = coapClient.get(); if (response != null) { //System.out.println(response.getResponseText()); try { JSONObject json = (JSONObject) JSONValue.parse(response.getResponseText()); myTicket.setAuthenticator(json.get("Authenticator").toString()); } catch (NullPointerException ex) { myTicket.reset(); } // Ask for ticket encoded = "{\"userPass\":\"" + Cryptonizer.encryptCoAP("Arrowhead", myTicket.getAuthenticator(), "BlackHole") + "\",\"userName\":\"BlackHole\"}"; //System.out.println(encoded); response = coapClient.put(encoded, MediaTypeRegistry.APPLICATION_JSON); if (response != null) { //System.out.println(response.getResponseText()); try { JSONObject json = (JSONObject) JSONValue.parse(response.getResponseText()); myTicket.setTicket(Cryptonizer.hexStringToByteArray(json.get("Ticket").toString())); myTicket.setExpireTime(Long.parseLong(json.get("ExpireTime").toString())); System.out.println("New Ticket: " + Cryptonizer.ByteArray2Hex(myTicket.getTicket())); } catch (NullPointerException ex) { myTicket.reset(); } } else { System.out.println("No response"); } } else { System.out.println("No response"); } } try { Thread.sleep(1000); // 1 s } catch (InterruptedException ex) { Thread.currentThread().interrupt(); // This should kill it propertly } } }
From source file:com.backelite.sonarqube.swift.issues.tailor.TailorRulesDefinition.java
private void loadRules(final NewRepository repository) throws IOException { Reader reader = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream(RULES_FILE), CharEncoding.UTF_8)); String jsonString = IOUtils.toString(reader); Object rulesObj = JSONValue.parse(jsonString); if (rulesObj != null) { JSONArray slRules = (JSONArray) rulesObj; for (Object obj : slRules) { JSONObject slRule = (JSONObject) obj; RulesDefinition.NewRule rule = repository.createRule((String) slRule.get("key")); rule.setName((String) slRule.get("name")); rule.setSeverity((String) slRule.get("severity")); rule.setHtmlDescription((String) slRule.get("description") + " (<a href=" + (String) slRule.get("styleguide") + ">" + (String) slRule.get("styleguide") + "</a>)"); }//from w w w .ja v a 2 s . co m } }
From source file:com.backelite.sonarqube.swift.issues.swiftlint.SwiftLintRulesDefinition.java
private void loadRules(NewRepository repository) throws IOException { Reader reader = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream(RULES_FILE), CharEncoding.UTF_8)); String jsonString = IOUtils.toString(reader); Object rulesObj = JSONValue.parse(jsonString); if (rulesObj != null) { JSONArray slRules = (JSONArray) rulesObj; for (Object obj : slRules) { JSONObject slRule = (JSONObject) obj; RulesDefinition.NewRule rule = repository.createRule((String) slRule.get("key")); rule.setName((String) slRule.get("name")); rule.setSeverity((String) slRule.get("severity")); rule.setHtmlDescription((String) slRule.get("description")); }// ww w . ja v a 2 s .co m } }
From source file:montodesktopcalculator.MontoManager.java
public final void listenForProducts() { if (null != listenerThread) { return;//from ww w .ja v a 2 s.co m } listenerThread = new Thread(new Runnable() { @Override public void run() { while (isConnected) { System.out.println("Waiting for messages..."); if (isConnected) { //Check to make sure we're connected String rawMessage = new String(fromMonto.recv()); System.out.println("Got message" + rawMessage); JSONObject message = (JSONObject) JSONValue.parse(rawMessage); listener.onProductRecieved(message.get("contents").toString()); } else { System.out.println("Not connected yet."); } try { Thread.sleep(10); } catch (Exception e) { } //Intentionally left blank } } }); listenerThread.start(); }
From source file:com.twosigma.beaker.core.rest.PublishRest.java
@POST @Path("github") @Produces(MediaType.APPLICATION_JSON)/*from w w w .j a va 2 s. c o m*/ public String notebook(@FormParam("json") String json, @FormParam("type") String type) throws IOException, ClientProtocolException { String files = "{\"Beaker Share\":{\"content\":\"" + JSONObject.escape(json) + "\"}}"; String body = "{\"description\":\"Beaker Share\",\"public\":true,\"files\":" + files + "}\n"; String response = null; try { response = Request.Post(this.gistUrl).useExpectContinue().version(HttpVersion.HTTP_1_1) .bodyString(body, ContentType.APPLICATION_JSON).execute().returnContent().asString(); } catch (Throwable t) { throw new GistPublishException(ExceptionUtils.getStackTrace(t)); } JSONObject parsed = (JSONObject) JSONValue.parse(response); String githubUrl = (String) parsed.get("html_url"); int slash = githubUrl.lastIndexOf("/"); if (slash < 0) { System.err.println("no slash found in github url: " + githubUrl); return githubUrl; } return this.sharingUrl + githubUrl.substring(slash); }