List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:me.timothy.ddd.entities.EntityPosition.java
@Override public void loadFrom(JSONObject jsonObject) { Set<?> keys = jsonObject.keySet(); for (Object o : keys) { if (o instanceof String) { String key = (String) o; switch (key.toLowerCase()) { case "x": x = getFloat(jsonObject, key); break; case "y": y = getFloat(jsonObject, key); break; case "width": width = getInt(jsonObject, key); break; case "height": height = getInt(jsonObject, key); break; default: logger.warn("Unknown key: " + key); }//from w ww.j a va 2s . com } } }
From source file:me.timothy.ddd.acheivements.Achievement.java
@Override public void loadFrom(JSONObject jsonObject) { Set<?> keys = jsonObject.keySet(); for (Object o : keys) { if (o instanceof String) { String key = (String) o; switch (key.toLowerCase()) { case "debug_name": debugName = getString(jsonObject, key); break; case "name": name = getString(jsonObject, key); break; case "text": text = getString(jsonObject, key); break; default: logger.warn("Unknown key: " + key); break; }/*w ww.j av a 2 s .co m*/ } } }
From source file:ch.newscron.encryption.EncryptionJUnitTest.java
public boolean compareJSONObjects(JSONObject one, JSONObject two) { if (one.keySet().size() != two.keySet().size()) { return false; }// w ww . ja v a 2 s . c o m Iterator<String> keysOne = one.keySet().iterator(); while (keysOne.hasNext()) { String key = (String) keysOne.next(); if (two.get(key) == null || !one.get(key).equals(two.get(key))) { return false; } } return true; }
From source file:com.bowprog.sql.constructeur.Table.java
public String createCol(JSONObject tableColonne) { String strQuery = "`id` INT NOT NULL AUTO_INCREMENT"; Collection<String> str = tableColonne.keySet(); for (String colName : str) { strQuery += ",`" + colName + "` "; JSONObject colonne = (JSONObject) tableColonne.get(colName); String type = (String) colonne.get("type"); strQuery += type;/*from w w w.j a va 2 s .com*/ if (colonne.containsKey("size")) { Long size = (Long) colonne.get("size"); strQuery += "(" + size + ")"; } if (colonne.containsKey("fk_table")) { String tableFK = (String) colonne.get("fk_table"); //fkSQL.add(" ALTER TABLE " + tableName + " ADD CONSTRAINT fk_" + tableFK + " FOREIGN KEY(" + colName + ") REFERENCES " + tableFK + "(id)"); } } strQuery += ",PRIMARY KEY (id)"; return strQuery; }
From source file:com.opensoc.enrichment.adapters.whois.WhoisHBaseAdapter.java
public boolean initializeAdapter() { Configuration conf = null;/*from w w w . j a va2 s . c om*/ conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", _quorum); conf.set("hbase.zookeeper.property.clientPort", _port); conf.set("zookeeper.session.timeout", "20"); conf.set("hbase.rpc.timeout", "20"); conf.set("zookeeper.recovery.retry", "1"); conf.set("zookeeper.recovery.retry.intervalmill", "1"); try { LOG.trace("[OpenSOC] Connecting to HBase"); LOG.trace("[OpenSOC] ZOOKEEPER = " + conf.get("hbase.zookeeper.quorum")); LOG.trace("[OpenSOC] CONNECTING TO HBASE WITH: " + conf); HConnection connection = HConnectionManager.createConnection(conf); LOG.trace("[OpenSOC] CONNECTED TO HBASE"); table = connection.getTable(_table_name); LOG.trace("--------CONNECTED TO TABLE: " + table); JSONObject tester = enrich("cisco.com"); if (tester.keySet().size() == 0) throw new IOException("Either HBASE is misconfigured or whois table is missing"); return true; } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:com.johncroth.histo.logging.LogHistogramParser.java
LogHistogramRecorder parseRecorderJson(JSONObject jo) { LogHistogramRecorder result = new LogHistogramRecorder(); for (Object o : jo.keySet()) { String metric = (String) o; LogHistogram hist = parseHistogramJson((JSONObject) jo.get(o)); result.getHistogramMap().put(metric, hist); }//from www .j a v a 2 s. com return result; }
From source file:Connector.Connector.java
private void setCredentials() { Map<String, String> env = System.getenv(); if (env.containsKey("VCAP_SERVICES")) { try {//from ww w . j a va 2s.c o m JSONParser parser = new JSONParser(); JSONObject vcap = (JSONObject) parser.parse(env.get("VCAP_SERVICES")); JSONObject service = null; for (Object key : vcap.keySet()) { String keyStr = (String) key; if (keyStr.toLowerCase().contains("tradeoff_analytics")) { service = (JSONObject) ((JSONArray) vcap.get(keyStr)).get(0); break; } } if (service != null) { JSONObject creds = (JSONObject) service.get("credentials"); String username = (String) creds.get("username"); String password = (String) creds.get("password"); this.username = username; this.password = password; System.out.println(username); System.out.println(password); } } catch (Exception e) { e.printStackTrace(System.err); } } }
From source file:io.fabric8.mq.controller.coordination.BrokerJMXPropertiesTest.java
public String getBrokerName() throws Exception { String type = "org.apache.activemq:type=Broker,*"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> result = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = result.getValue(); Assert.assertNotNull(jsonObject);// ww w.j a va 2 s. co m Object key = jsonObject.keySet().iterator().next(); JSONObject value = (JSONObject) jsonObject.get(key); String name = value.values().iterator().next().toString(); System.err.println("BROKER NAME = " + name); Assert.assertNotNull(value); Assert.assertEquals(BROKER_NAME, name); return name; }
From source file:consistencyTests.util.StringToStringMap.java
public StringToStringMap(String contentOfMapAsJson) throws ParseException { super();/*from w w w . j a v a2 s . c o m*/ JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(contentOfMapAsJson); @SuppressWarnings("unchecked") Set<String> keys = jsonObj.keySet(); for (String key : keys) { Object value = jsonObj.get(key); // Remove key from json string if (value instanceof String) { super.put(key, (String) value); } } }
From source file:com.netflix.priam.cassandra.extensions.PriamStartupAgent.java
private void setExtraEnvParams(String extraEnvParams) { try {//from ww w . j a v a2 s . c om if (null != extraEnvParams && extraEnvParams.length() > 0) { JSONParser parser = new JSONParser(); Object obj = parser.parse(extraEnvParams); JSONObject jsonObj = (JSONObject) obj; if (jsonObj.size() > 0) { for (Iterator iterator = jsonObj.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String val = (String) jsonObj.get(key); if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)) { System.setProperty(key.trim(), val.trim()); } } } } } catch (Exception e) { System.out.println( "Failed to parse extra env params: " + extraEnvParams + ". However, ignoring the exception."); e.printStackTrace(); } }