org.json.simple.JSONObject.keySet()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.json.simple.JSONObject.keySet()方法的一些代码示例,展示了JSONObject.keySet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.keySet()方法的具体详情如下:
包路径:org.json.simple.JSONObject
类名称:JSONObject
方法名:keySet

JSONObject.keySet介绍

暂无

代码示例

代码示例来源:origin: Netflix/Priam

private void setExtraEnvParams(String extraEnvParams) {
    try {
      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();
    }
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void populateMap( Map<ObjectId, Map<Integer, Map<String, String>>> attributeMap, JSONObject jsonObject ) {
 for ( Object objectId : jsonObject.keySet() ) {
  JSONObject nrsObject = (JSONObject) jsonObject.get( objectId );
  for ( Object nrKey : nrsObject.keySet() ) {
   JSONObject nrObject = (JSONObject) nrsObject.get( nrKey );
   for ( Object stringKey : nrObject.keySet() ) {
    setAttribute( attributeMap, new StringObjectId( objectId.toString() ), Integer.valueOf( nrKey.toString() ),
      stringKey.toString(), nrObject.get( stringKey ).toString() );
   }
  }
 }
}

代码示例来源:origin: ethereum/ethereumj

public TestSuite(JSONObject testCaseJSONObj) throws ParseException {
  for (Object key : testCaseJSONObj.keySet()) {
    Object testCaseJSON = testCaseJSONObj.get(key);
    TestCase testCase = new TestCase(key.toString(), (JSONObject) testCaseJSON);
    testList.add(testCase);
  }
}

代码示例来源:origin: Netflix/Priam

for (Object key : jsonObject.keySet()) {
  JSONObject msg = (JSONObject) jsonObject.get(key);
  if (msg.get("Token") == null) {

代码示例来源:origin: ethereum/ethereumj

public AccountState(byte[] address, JSONObject accountState) {
  this.address = address;
  String balance = accountState.get("balance").toString();
  String code = (String) accountState.get("code");
  String nonce = accountState.get("nonce").toString();
  JSONObject store = (JSONObject) accountState.get("storage");
  this.balance = TestCase.toBigInt(balance).toByteArray();
  if (code != null && code.length() > 2)
    this.code = Hex.decode(code.substring(2));
  else
    this.code = ByteUtil.EMPTY_BYTE_ARRAY;
  this.nonce = TestCase.toBigInt(nonce).toByteArray();
  int size = store.keySet().size();
  Object[] keys = store.keySet().toArray();
  for (int i = 0; i < size; ++i) {
    String keyS = keys[i].toString();
    String valS = store.get(keys[i]).toString();
    byte[] key = Utils.parseData(keyS);
    byte[] value = Utils.parseData(valS);
    storage.put(DataWord.of(key), DataWord.of(value));
  }
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testPremineFromJSON() throws ParseException {
  JSONParser parser = new JSONParser();
  JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS);
  Set keys = genesisMap.keySet();
  Trie state = new SecureTrie((byte[]) null);
  for (Object key : keys) {
    JSONObject val = (JSONObject) genesisMap.get(key);
    String denom = (String) val.keySet().toArray()[0];
    String value = (String) val.values().toArray()[0];
    BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value));
    AccountState acctState = new AccountState(BigInteger.ZERO, wei);
    state.put(Hex.decode(key.toString()), acctState.getEncoded());
  }
  logger.info("root: " + Hex.toHexString(state.getRootHash()));
  assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(state.getRootHash()));
}

代码示例来源:origin: ethereum/ethereumj

this.out = ByteUtil.EMPTY_BYTE_ARRAY;
for (Object key : preJSON.keySet()) {
for (Object key : postJSON.keySet()) {

代码示例来源:origin: apache/metron

@SuppressWarnings("unchecked")
private void removeEmptyFields(JSONObject json) {
 Iterator<Object> keyIter = json.keySet().iterator();
 while (keyIter.hasNext()) {
  Object key = keyIter.next();
  Object value = json.get(key);
  if (null == value || "".equals(value.toString())) {
   keyIter.remove();
  }
 }
}

代码示例来源:origin: apache/metron

public void removeTimingFields(JSONObject message) {
  ImmutableSet keys = ImmutableSet.copyOf(message.keySet());
  for (Object key : keys) {
   if (key.toString().endsWith(".ts")) {
    message.remove(key);
   }
  }
 }
}

代码示例来源:origin: larsgeorge/hbase-book

protected Map<String, String> parseStringToMap(String line) {
 try {
  Map<String, String> values = Maps.newHashMap();
  JSONObject jsonObj = (JSONObject) jsonParser.parse(line);
  for (Object key : jsonObj.keySet()) {
   Object value = jsonObj.get(key);
   values.put(key.toString(), value != null ? value.toString() : null);
  }
  return values;
 } catch (ParseException e) {
  LOG.warn("Could not json-decode string: " + line, e);
  return null;
 } catch (NumberFormatException e) {
  LOG.warn("Very big number exceeds the scale of long: " + line, e);
  return null;
 }
}

代码示例来源:origin: apache/metron

public static JSONObject adjustKeys(JSONObject enrichedMessage, JSONObject enrichedField, String field, String prefix) {
 if ( !enrichedField.isEmpty()) {
  for (Object enrichedKey : enrichedField.keySet()) {
   if(!StringUtils.isEmpty(prefix)) {
    enrichedMessage.put(field + "." + enrichedKey, enrichedField.get(enrichedKey));
   }
   else {
    enrichedMessage.put(enrichedKey, enrichedField.get(enrichedKey));
   }
  }
 }
 return enrichedMessage;
}

代码示例来源:origin: apache/metron

@SuppressWarnings("unchecked")
 @Override
 public JSONObject enrich(CacheKey k) {
  String metadata = k.coerceValue(String.class);

  if(!_known_hosts.containsKey(metadata))
   return new JSONObject();

  JSONObject enrichment = new JSONObject();
  String prefix = "known_info.";
  JSONObject knownInfo = _known_hosts.get(metadata);
  for(Object key: knownInfo.keySet()) {
   enrichment.put(prefix + key, knownInfo.get(key));
  }
  //enrichment.put("known_info", _known_hosts.get(metadata));
  return enrichment;
 }
}

代码示例来源:origin: jitsi/jitsi-videobridge

public static ShutdownIQ deserializeShutdownIQ(
  JSONObject requestJSONObject)
{
  String element = (String) requestJSONObject.keySet().iterator().next();
  return ShutdownIQ.isValidElementName(element) ?
    ShutdownIQ.createShutdownIQ(element) : null;
}

代码示例来源:origin: apache/metron

private static JSONObject join(JSONObject left, JSONObject right) {
 JSONObject message = new JSONObject();
 message.putAll(left);
 message.putAll(right);
 List<Object> emptyKeys = new ArrayList<>();
 for(Object key : message.keySet()) {
  Object value = message.get(key);
  if(value == null || value.toString().length() == 0) {
   emptyKeys.add(key);
  }
 }
 for(Object o : emptyKeys) {
  message.remove(o);
 }
 return message;
}

代码示例来源:origin: apache/tika

/**
 * Loads the class to
 *
 * @param stream label index stream
 * @return Map of integer -&gt; label name
 * @throws IOException    when the stream breaks unexpectedly
 * @throws ParseException when the input doesn't contain a valid JSON map
 */
public Map<Integer, String> loadClassIndex(InputStream stream)
    throws IOException, ParseException {
  String content = IOUtils.toString(stream);
  JSONObject jIndex = (JSONObject) new JSONParser().parse(content);
  Map<Integer, String> classMap = new HashMap<>();
  for (Object key : jIndex.keySet()) {
    JSONArray names = (JSONArray) jIndex.get(key);
    classMap.put(Integer.parseInt(key.toString()),
        names.get(names.size() - 1).toString());
  }
  return classMap;
}

代码示例来源:origin: apache/metron

@Override
public JSONObject joinMessages(Map<String, Tuple> streamMessageMap, MessageGetStrategy messageGetStrategy) {
 JSONObject message = new JSONObject();
 for (String key : streamMessageMap.keySet()) {
  Tuple tuple = streamMessageMap.get(key);
  JSONObject obj = (JSONObject) messageGetStrategy.get(tuple);
  message.putAll(obj);
 }
 List<Object> emptyKeys = new ArrayList<>();
 for(Object key : message.keySet()) {
  Object value = message.get(key);
  if(value == null || value.toString().length() == 0) {
   emptyKeys.add(key);
  }
 }
 for(Object o : emptyKeys) {
  message.remove(o);
 }
 message.put(getClass().getSimpleName().toLowerCase() + ".joiner.ts", "" + System.currentTimeMillis());
 return  message;
}

代码示例来源:origin: apache/metron

private TupleBasedDocument createDocument(JSONObject message,
                     Tuple tuple,
                     String sensorType,
                     FieldNameConverter fieldNameConverter) {
 // transform the message fields to the source fields of the indexed document
 JSONObject source = new JSONObject();
 for(Object k : message.keySet()){
  copyField(k.toString(), message, source, fieldNameConverter);
 }
 // define the document id
 String guid = ConversionUtils.convert(source.get(Constants.GUID), String.class);
 if(guid == null) {
  LOG.warn("Missing '{}' field; document ID will be auto-generated.", Constants.GUID);
 }
 // define the document timestamp
 Long timestamp = null;
 Object value = source.get(TIMESTAMP.getName());
 if(value != null) {
  timestamp = Long.parseLong(value.toString());
 } else {
  LOG.warn("Missing '{}' field; timestamp will be set to system time.", TIMESTAMP.getName());
 }
 return new TupleBasedDocument(source, guid, sensorType, timestamp, tuple);
}

代码示例来源:origin: apache/metron

@Override
 public void removeTimingFields(JSONObject message) {
  ImmutableSet keys = ImmutableSet.copyOf(message.keySet());
  for(Object key: keys) {
   if (key.toString().contains("splitter.begin.ts")) {
    message.remove(key);
   }
  }
 }
}

代码示例来源:origin: apache/metron

public Collection<SolrInputDocument> toDocs(Iterable<JSONObject> messages) {
 Collection<SolrInputDocument> ret = new ArrayList<>();
 for(JSONObject message: messages) {
  SolrInputDocument document = new SolrInputDocument();
  for (Object key : message.keySet()) {
   Object value = message.get(key);
   if (value instanceof Iterable) {
    for (Object v : (Iterable) value) {
     document.addField("" + key, v);
    }
   } else {
    document.addField("" + key, value);
   }
  }
  if (!document.containsKey(Constants.GUID)) {
   document.addField(Constants.GUID, UUID.randomUUID().toString());
  }
  ret.add(document);
 }
 return ret;
}

代码示例来源:origin: rhuss/jolokia

/**
 * Get the name of all attributes fetched for a certain MBean name. If the request was
 * performed for a single MBean, then the given name must match that of the MBean name
 * provided in the request. If <code>null</code> is given as argument, then this method
 * will return all attributes for the single MBean given in the request
 *
 * @param pObjectName MBean for which to get the attribute names,
 * @return a collection of attribute names
 */
public Collection<String> getAttributes(ObjectName pObjectName) {
  ObjectName requestMBean = getRequest().getObjectName();
  if (requestMBean.isPattern()) {
    // We need to got down one level in the returned values
    JSONObject attributes = getAttributesForObjectNameWithPatternRequest(pObjectName);
    return attributes.keySet();
  } else {
    if (pObjectName != null && !pObjectName.equals(requestMBean)) {
      throw new IllegalArgumentException("Given ObjectName " + pObjectName + " doesn't match with" +
          " the single ObjectName " + requestMBean + " given in the request");
    }
    return getAttributes();
  }
}

相关文章