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

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

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

JSONObject.entrySet介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

private boolean compareObjects(JSONObject expectedMap, JSONObject actualMap) {
 // each key-value of expected map must exist in actual map
 for (Map.Entry<Object, Object> expectedEntry : (Set<Map.Entry<Object, Object>>) expectedMap.entrySet()) {
  Object key = expectedEntry.getKey();
  if (shouldIgnoreField(key)) {
   continue;
  }
  if (!actualMap.containsKey(key)) {
   return false;
  }
  if (!compare(expectedEntry.getValue(), actualMap.get(key))) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Reloads from the file.
 */
public void load() {
  entries.clear();
  if (file.exists()) {
    try (Reader reader = new FileReader(file)) {
      JSONArray jsonArray = (JSONArray) new JSONParser().parse(reader);
      for (Object object : jsonArray) {
        JSONObject jsonObj = (JSONObject) object;
        Map<String, String> map = new HashMap<>(jsonObj.size());
        for (Object jsonEntry : jsonObj.entrySet()) {
          Entry<?, ?> entry = (Map.Entry<?, ?>) jsonEntry;
          map.put(entry.getKey().toString(), entry.getValue().toString());
        }
        entries.add(readEntry(map));
      }
    } catch (Exception ex) {
      GlowServer.logger.log(Level.SEVERE, "Error reading from: " + file, ex);
    }
  } else {
    //importLegacy();
    save();
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(new FileReader(statsFile));
for (Object obj : json.entrySet()) {
  Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj;
  Long longValue = null;

代码示例来源:origin: linkedin/indextank-engine

private Map<String, String> prepareProperties(JSONObject jo) {
  Map<String, String> properties = Maps.newHashMap();
  if(jo == null) {
    return properties;
  }
  for(Object o: jo.entrySet()) {
    @SuppressWarnings("rawtypes")
    Map.Entry e = (Map.Entry) o;
    Object key = e.getKey();
    Object value = e.getValue();
    properties.put(valueOf(key), valueOf(value));
  }
  return properties;
}

代码示例来源:origin: linkedin/indextank-engine

private Map<Integer, Double> prepareBoosts(JSONObject jo) {
  Map<Integer, Double> dynamicBoosts = Maps.newHashMap();
  if(jo == null) {
    return dynamicBoosts;
  }
  for(Object o: jo.entrySet()) {
    @SuppressWarnings("rawtypes")
    Map.Entry e = (Map.Entry) o;
    Object key = e.getKey();
    Object value = e.getValue();
    dynamicBoosts.put(parseInt(valueOf(key)), parseDouble(valueOf(value)));
  }
  return dynamicBoosts;
}

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

private Object truncateJSONObject(JSONObject pValue, int pMaxDepth) {
  if (pMaxDepth == 0) {
    return 1;
  }
  JSONObject ret = new JSONObject();
  Set<Map.Entry> entries = pValue.entrySet();
  for (Map.Entry entry : entries) {
    Object value = entry.getValue();
    Object key = entry.getKey();
    if (value instanceof JSONObject) {
      ret.put(key, truncateJSONObject((JSONObject) value, pMaxDepth - 1));
    } else {
      ret.put(key,value);
    }
  }
  return ret;
}

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

public static Map<Payload,Object> parseData(byte[] pData, int pLength) throws IOException {
  JSONParser parser = new JSONParser();
  ByteArrayInputStream is = new ByteArrayInputStream(pData,0,pLength);
  try {
    JSONObject inMsg = (JSONObject) parser.parse(new InputStreamReader(is, "UTF-8"));
    Map<Payload, Object> data = new HashMap<Payload, Object>();
    for (Map.Entry entry : (Set<Map.Entry>) inMsg.entrySet()) {
      try {
        data.put(Payload.fromKey(entry.getKey().toString()), entry.getValue());
      } catch (IllegalArgumentException exp) {
        // We simply ignore key which are unknown
      }
    }
    return data;
  } catch (ParseException e) {
    throw new IOException("Cannot parse discovery message as JSON",e);
  }
}

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

public static void deserializeParameters(
    JSONObject parameters,
    PayloadTypePacketExtension payloadTypeIQ)
{
  if (parameters != null)
  {
    for (Map.Entry<Object, Object> e
          : (Iterable<Map.Entry<Object, Object>>) parameters
              .entrySet())
    {
      Object name = e.getKey();
      Object value = e.getValue();
      if ((name != null) || (value != null))
      {
        payloadTypeIQ.addParameter(
            new ParameterPacketExtension(
                Objects.toString(name, null),
                Objects.toString(value, null)));
      }
    }
  }
}

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

.entrySet())

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

private EnrichmentValue getValue( JSONObject message
                , Set<String> keyColumns
                , Set<String> valueColumns
                )
{
 Map<String, Object> metadata = new HashMap<>();
 if(valueColumns == null || valueColumns.isEmpty()) {
  for (Object kv : message.entrySet()) {
   Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) kv;
   if (!keyColumns.contains(entry.getKey())) {
    addMetadataEntry(metadata, entry);
   }
  }
  return new EnrichmentValue(metadata);
 }
 else {
  for (Object kv : message.entrySet()) {
   Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) kv;
   if (valueColumns.contains(entry.getKey())) {
    addMetadataEntry(metadata, entry);
   }
  }
  return new EnrichmentValue(metadata);
 }
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testOutput() throws ParseException {
  List<MetricName> inputMetricNames = new ArrayList<MetricName>() {{
    add(new MetricName("foo", false));
    add(new MetricName("bar", false));
  }};
  String output = handler.getSerializedJSON(inputMetricNames);
  JSONParser jsonParser = new JSONParser();
  JSONArray tokenInfos = (JSONArray) jsonParser.parse(output);
  Assert.assertEquals("Unexpected result size", 2, tokenInfos.size());
  Set<String> expectedOutputSet = new HashSet<String>();
  for (MetricName metricName : inputMetricNames) {
    expectedOutputSet.add(metricName.getName() + "|" + metricName.isCompleteName());
  }
  Set<String> outputSet = new HashSet<String>();
  for (int i = 0; i< inputMetricNames.size(); i++) {
    JSONObject object = (JSONObject) tokenInfos.get(i);
    Iterator it = object.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      outputSet.add(entry.getKey() + "|" + entry.getValue());
    }
  }
  Assert.assertEquals("Unexpected size", expectedOutputSet.size(), outputSet.size());
  Assert.assertTrue("Output contains no more elements than expected", expectedOutputSet.containsAll(outputSet));
  Assert.assertTrue("Output contains no less elements than expected", outputSet.containsAll(expectedOutputSet));
}

代码示例来源:origin: rackerlabs/blueflood

final Set<Map.Entry<String, Object>> statsSet = filterStatsObject.entrySet();
final Set<Map.Entry<String, Object>> statsSet = filterStatsObject.entrySet();
for (Map.Entry<String, Object> stat : statsSet) {
  object.put(stat.getKey(), stat.getValue());

代码示例来源:origin: org.esbtools.message.admin/esb-message-admin-common

private static Map<String, String> getMap(JSONObject jsonMap) {
  Map<String,String> map = new HashMap<>();
  for(Map.Entry<String,String> entry : (Set<Map.Entry<String,String>>)jsonMap.entrySet()) {
    map.put(entry.getKey(),entry.getValue());
  }
  return map;
}

代码示例来源:origin: stackoverflow.com

JSONObject json = getJsonFromFile(filePath);
HashMap<String, Number> entries = new HashMap<>();

for (Object obj : json.entrySet()) {
  Entry<String, Number> mapEntry = (Entry<String, Number>) obj;
  System.out.println("key: " + mapEntry.getKey() + " value: " + mapEntry.getValue());
  entries.put(mapEntry.getKey(), mapEntry.getValue());
}

代码示例来源:origin: stackoverflow.com

JSONObject parse = JSON.parseObject("");
 for (Map.Entry<String, Object> entry : parse.entrySet()) {
   System.out.println(entry.getKey() + "=" + entry.getValue());
 }

代码示例来源:origin: stackoverflow.com

String serializedMap = prop.getProperty("wordMap");
JSONObject json = (JSONObject) JSONValue.parse(serializedMap);
Map<String, String> wordMap = new HashMap<>();

for (Map.Entry<String,Object> entry : json.entrySet()) {
  wordMap.put(entry.getKey(), (String) entry.getValue());
}

代码示例来源:origin: stackoverflow.com

JSONObject obj = JSONObject.fromObject(strRepresentation);
Iterator i = obj.entrySet().iterator();
while (i.hasNext()) {
  Map.Entry e = (Map.Entry)i.next();
  System.out.println("Key: " + e.getKey());
  System.out.println("Value: " + e.getValue());
}

代码示例来源:origin: BiglySoftware/BiglyBT

public void toString( StringBuilder sb ){
  sb.append( "{" );
  Iterator iter=entrySet().iterator();
  boolean first = true;
  while(iter.hasNext()){
    if ( first ){
      first = false;
    }else{
      sb.append( "," );
    }
    Map.Entry entry=(Map.Entry)iter.next();
    toString(sb, entry.getKey().toString(),entry.getValue());
  }
  sb.append( "}" );
}

代码示例来源:origin: BiglySoftware/BiglyBT

public String toString(){
  ItemList list=new ItemList();
  Iterator<Map.Entry<String, Object>> iter=entrySet().iterator();
  while(iter.hasNext()){
    Map.Entry<String, Object> entry=iter.next();
    list.add(toString(entry.getKey().toString(),entry.getValue()));
  }
  return "{"+list.toString()+"}";
}

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

public Void call() throws Exception {
    URL url = createURL(RestConstants.ADMIN_UPDATE_SHARELIB, Collections.EMPTY_MAP);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
    assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE));
    JSONObject json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
    assertEquals(1, json.entrySet().size());
    return null;
  }
});

相关文章