Codota Logo
JSONArray.size
Code IndexAdd Codota to your IDE (free)

How to use
size
method
in
org.json.simple.JSONArray

Best Java code snippets using org.json.simple.JSONArray.size (Showing top 20 results out of 1,035)

Refine searchRefine arrow

  • JSONObject.get
  • Common ways to obtain JSONArray
private void myMethod () {
JSONArray j =
  • Codota Iconnew JSONArray()
  • Codota IconJSONObject json;Object object;(JSONArray) json.get(object)
  • Codota IconString s;(JSONArray) JSONValue.parse(s)
  • Smart code suggestions by Codota
}
origin: scouter-project/scouter

private static PerfCounterPack extractPerfCounterPack(JSONArray perfJson, String objName) {
  PerfCounterPack perfPack = new PerfCounterPack();
  perfPack.time = System.currentTimeMillis();
  perfPack.timetype = TimeTypeEnum.REALTIME;
  perfPack.objName = objName;
  for (int i = 0; i < perfJson.size(); i++) {
    JSONObject perf = (JSONObject) perfJson.get(i);
    String name = (String) perf.get("name");
    Number value = (Number) perf.get("value");
    perfPack.data.put(name, new FloatValue(value.floatValue()));
  }
  return perfPack;
}

origin: GlowstoneMC/Glowstone

  /**
   * Reads a LootItem from its JSON form.
   *
   * @param object a LootItem in JSON form
   */
  public LootItem(JSONObject object) {
    defaultItem = new DefaultLootItem((JSONObject) object.get("default"));
    if (object.containsKey("conditions")) {
      JSONArray array = (JSONArray) object.get("conditions");
      conditionalItems = new ConditionalLootItem[array.size()];
      for (int i = 0; i < array.size(); i++) {
        JSONObject json = (JSONObject) array.get(i);
        conditionalItems[i] = new ConditionalLootItem(json);
      }
    } else {
      conditionalItems = NO_ITEMS;
    }
  }
}
origin: GlowstoneMC/Glowstone

/**
 * Reads a GlowPlayerProfile from a JSON object.
 *
 * @param json a player profile in JSON form
 * @return {@code json} as a GlowPlayerProfile
 */
public static GlowPlayerProfile fromJson(JSONObject json) {
  String name = (String) json.get("name");
  String id = (String) json.get("id");
  JSONArray propsArray = (JSONArray) json.get("properties");
  // Parse UUID
  UUID uuid;
  try {
    uuid = UuidUtils.fromFlatString(id);
  } catch (IllegalArgumentException ex) {
    GlowServer.logger.log(Level.SEVERE, "Returned authentication UUID invalid: " + id);
    return null;
  }
  // Parse properties
  Collection<ProfileProperty> properties = new HashSet<>(propsArray.size());
  for (Object obj : propsArray) {
    JSONObject propJson = (JSONObject) obj;
    String propName = (String) propJson.get("name");
    String value = (String) propJson.get("value");
    String signature = (String) propJson.get("signature");
    properties.add(new ProfileProperty(propName, value, signature));
  }
  return new GlowPlayerProfile(name, uuid, properties, true);
}
origin: apache/storm

  return null;
String downloadURI = (String) json.get("downloadUri");
JSONArray msg = (JSONArray) json.get("children");
if (msg == null || msg.size() == 0) {
  LOG.error("Expected directory children not present");
  return null;
String uri = (String) newest.get("uri");
if (uri == null) {
  LOG.error("Expected directory uri not present");
origin: GlowstoneMC/Glowstone

  /**
   * Parses a loot table from JSON.
   *
   * @param object a loot table in JSON form
   */
  public EntityLootTable(JSONObject object) {
    if (object.containsKey("experience")) { // NON-NLS
      this.experience
          = new LootRandomValues((JSONObject) object.get("experience")); // NON-NLS
    } else {
      this.experience = null;
    }
    if (object.containsKey("items")) { // NON-NLS
      JSONArray array = (JSONArray) object.get("items"); // NON-NLS
      this.items = new LootItem[array.size()];
      for (int i = 0; i < array.size(); i++) {
        JSONObject json = (JSONObject) array.get(i);
        this.items[i] = new LootItem(json);
      }
    } else {
      this.items = NO_ITEMS;
    }
  }
}
origin: GlowstoneMC/Glowstone

securityKey = (String) payload.get("s"); // Not used by us anywhere
name = (String) payload.get("n");
hostname = (String) payload.get("h");
uuid = UuidUtils.fromFlatString((String) payload.get("u"));
address = new InetSocketAddress(
  JSONArray props = (JSONArray) payload.get("p");
  properties = new ArrayList<>(props.size());
  for (Object obj : props) {
    JSONObject prop = (JSONObject) obj;
properties = new ArrayList<>(jsonProperties.size());
for (Object obj : jsonProperties) {
  JSONObject propJson = (JSONObject) obj;
origin: GlowstoneMC/Glowstone

String name = (String) json.get("name"); // NON-NLS
String id = (String) json.get("id"); // NON-NLS
JSONArray propsArray = (JSONArray) json.get("properties"); // NON-NLS
List<ProfileProperty> properties = new ArrayList<>(propsArray.size());
for (Object obj : propsArray) {
  JSONObject propJson = (JSONObject) obj;
origin: scouter-project/scouter

try {
  JSONObject json = (JSONObject) parser.parse(in);
  JSONObject objectInfo = (JSONObject) json.get("object");
  JSONArray countersArray = (JSONArray) json.get("counters");
  String objType = (String) objectInfo.get("type");
      family.setName(objType + "." + (Math.random() * 100));
    int counterSize = countersArray.size();
    for (int i = 0; i < counterSize; i++) {
      JSONObject counterInfo = (JSONObject)countersArray.get(i);
      addObjectType.setDisplayName(objectType.getDisplayName());
    int counterSize = countersArray.size();
    for (int i = 0; i < counterSize; i++) {
      JSONObject counterInfo = (JSONObject)countersArray.get(i);
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: rhuss/jolokia

private boolean checkForFullTabularDataRepresentation(JSONObject pValue, TabularType pType) {
  if (pValue.containsKey("indexNames") && pValue.containsKey("values") && pValue.size() == 2) {
    Object jsonVal = pValue.get("indexNames");
    if (!(jsonVal instanceof JSONArray)) {
      throw new IllegalArgumentException("Index names for tabular data must given as JSON array, not " + jsonVal.getClass());
    }
    JSONArray indexNames = (JSONArray) jsonVal;
    List<String> tabularIndexNames = pType.getIndexNames();
    if (indexNames.size() != tabularIndexNames.size()) {
      throw new IllegalArgumentException("Given array with index names must have " + tabularIndexNames.size() + " entries " +
                        "(given: " + indexNames + ", required: " + tabularIndexNames + ")");
    }
    for (Object index : indexNames) {
      if (!tabularIndexNames.contains(index.toString())) {
        throw new IllegalArgumentException("No index with name '" + index + "' known " +
                          "(given: " + indexNames + ", required: " + tabularIndexNames + ")");
      }
    }
    return true;
  }
  return false;
}
origin: apache/tika

if (response.getStatusLine().getStatusCode() == 200) {
  JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);
  JSONArray jCaptions = (JSONArray) jReply.get("captions");
  for (int i = 0; i < jCaptions.size(); i++) {
    JSONObject jCaption = (JSONObject) jCaptions.get(i);
    String sentence = (String) jCaption.get("sentence");
    Double confidence = (Double) jCaption.get("confidence");
    capObjs.add(new CaptionObject(sentence, LABEL_LANG, confidence));
origin: jitsi/jitsi-videobridge

.get(SourceGroupPacketExtension.SEMANTICS_ATTR_NAME);
  .get(JSONSerializer.SOURCES);
  && ((JSONArray)sourcesObject).size() != 0)
origin: apache/tika

JSONObject jsonObject = convertToJSONObject(result);
JSONArray measurements = convertToJSONArray(jsonObject, "measurements");
for(int i=0; i<measurements.size(); i++){
  JSONObject quantity = (JSONObject) convertToJSONObject(measurements.get(i).toString()).get("quantity");
  if(quantity!=null) {
    if (quantity.containsKey("rawValue")) {
      String measurementNumber = (String) convertToJSONObject(quantity.toString()).get("rawValue");
      measurementString.append(measurementNumber);
      measurementString.append(" ");
      String normalizedMeasurementNumber = convertToJSONObject(quantity.toString()).get("normalizedQuantity").toString();
      normalizedMeasurementString.append(normalizedMeasurementNumber);
      normalizedMeasurementString.append(" ");
origin: i2p/i2p.i2p

  return null;
Number status = (Number) map.get("Status");
if (status == null || status.intValue() != 0) {
  log("Bad status: " + status);
  return null;
JSONArray list = (JSONArray) map.get("Answer");
if (list == null || list.isEmpty()) {
  log("No answer");
  return null;
log(list.size() + " answers");
String hostAnswer = host + '.';
for (Object o : list) {
  try {
    JSONObject a = (JSONObject) o;
    String data = (String) a.get("data");
    if (data == null) {
      log("no data");
origin: rackerlabs/blueflood

@Test
public void testSets() throws Exception {
  final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
  final MetricData metricData = new MetricData(
      FakeMetricDataGenerator.generateFakeSetRollupPoints(),
      "unknown");
  JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_SET);
  final JSONArray data = (JSONArray)metricDataJSON.get("values");
  
  Assert.assertEquals(5, data.size());
  for (int i = 0; i < data.size(); i++) {
    final JSONObject dataJSON = (JSONObject)data.get(i);
    
    Assert.assertNotNull(dataJSON.get("numPoints"));
    Assert.assertEquals(Sets.newHashSet(i, i % 2, i / 2).size(), dataJSON.get("numPoints"));
  }
}

origin: rackerlabs/blueflood

@Test
public void setTimers() throws Exception {
  final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
  final MetricData metricData = new MetricData(
      FakeMetricDataGenerator.generateFakeTimerRollups(),
      "unknown");
  
  JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_TIMER);
  final JSONArray data = (JSONArray)metricDataJSON.get("values");
  
  Assert.assertEquals(5, data.size());
  for (int i = 0; i < data.size(); i++) {
    final JSONObject dataJSON = (JSONObject)data.get(i);
    
    Assert.assertNotNull(dataJSON.get("numPoints"));
    Assert.assertNotNull(dataJSON.get("average"));
    Assert.assertNotNull(dataJSON.get("rate"));
    
    // bah. I'm too lazy to check equals.
  }
}

origin: rackerlabs/blueflood

@Test
public void testCounters() throws Exception {
  final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
  final MetricData metricData = new MetricData(
      FakeMetricDataGenerator.generateFakeCounterRollupPoints(), 
      "unknown");
  JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_COUNTER);
  final JSONArray data = (JSONArray)metricDataJSON.get("values");
  
  Assert.assertEquals(5, data.size());
  for (int i = 0; i < data.size(); i++) {
    final JSONObject dataJSON = (JSONObject)data.get(i);
    
    Assert.assertNotNull(dataJSON.get("numPoints"));
    Assert.assertEquals(i+1, dataJSON.get("numPoints"));
    Assert.assertNotNull(dataJSON.get("sum"));
    Assert.assertEquals((long) (i + 1000), dataJSON.get("sum"));
    Assert.assertNull(dataJSON.get("rate"));
  }
}

origin: rackerlabs/blueflood

@Test
public void testGauges() throws Exception {
  final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
  final MetricData metricData = new MetricData(
      FakeMetricDataGenerator.generateFakeGaugeRollups(),
      "unknown");
  JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_GAUGE);
  final JSONArray data = (JSONArray)metricDataJSON.get("values");
  
  Assert.assertEquals(5, data.size());
  for (int i = 0; i < data.size(); i++) {
    final JSONObject dataJSON = (JSONObject)data.get(i);
    
    Assert.assertNotNull(dataJSON.get("numPoints"));
    Assert.assertEquals(1L, dataJSON.get("numPoints"));
    Assert.assertNotNull("latest");
    Assert.assertEquals(i, dataJSON.get("latest"));
    
    // other fields were filtered out.
    Assert.assertNull(dataJSON.get(MetricStat.AVERAGE.toString()));
    Assert.assertNull(dataJSON.get(MetricStat.VARIANCE.toString()));
    Assert.assertNull(dataJSON.get(MetricStat.MIN.toString()));
    Assert.assertNull(dataJSON.get(MetricStat.MAX.toString()));
  }
}

origin: rackerlabs/blueflood

@Test
public void testTransformRollupDataAtFullRes() throws Exception {
  final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer();
  final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeFullResPoints(), "unknown");
  JSONObject metricDataJSON = serializer.transformRollupData(metricData, filterStats);
  final JSONArray data = (JSONArray) metricDataJSON.get("values");
  // Assert that we have some data to test
  Assert.assertTrue(data.size() > 0);
  for (int i = 0; i < data.size(); i++) {
    final JSONObject dataJSON = (JSONObject) data.get(i);
    final Points.Point<SimpleNumber> point = (Points.Point<SimpleNumber>) metricData.getData().getPoints().get(dataJSON.get("timestamp"));
    Assert.assertEquals(point.getData().getValue(), dataJSON.get("average"));
    Assert.assertEquals(point.getData().getValue(), dataJSON.get("min"));
    Assert.assertEquals(point.getData().getValue(), dataJSON.get("max"));
    // Assert that variance isn't present
    Assert.assertNull(dataJSON.get("variance"));
    // Assert numPoints isn't present
    Assert.assertNull(dataJSON.get("numPoints"));
    // Assert sum isn't present
    Assert.assertNull(dataJSON.get("sum"));
  }
}
origin: rackerlabs/blueflood

final JSONArray data = (JSONArray) metricDataJSON.get("values");
Assert.assertTrue(data.size() > 0);
for (int i = 0; i < data.size(); i++) {
  final JSONObject dataJSON = (JSONObject) data.get(i);
  final Points.Point point = (Points.Point) metricData.getData().getPoints().get(dataJSON.get("timestamp"));
  Assert.assertEquals(numPoints, dataJSON.get("numPoints"));
org.json.simpleJSONArraysize

Popular methods of JSONArray

  • <init>
    Constructs a JSONArray containing the elements of the specified collection, in the order they are re
  • add
  • get
  • toJSONString
  • iterator
  • addAll
  • isEmpty
  • toString
  • toArray
  • writeJSONString
  • contains
  • remove
  • contains,
  • remove,
  • set,
  • clear,
  • forEach,
  • getJsonObject,
  • listIterator,
  • subList

Popular in Java

  • Creating JSON documents from java classes using gson
  • setScale (BigDecimal)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • getContentResolver (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Socket (java.net)
    Provides a client-side TCP socket.
  • ConcurrentHashMap (java.util.concurrent)
    A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updat
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now