Example usage for org.json.simple JSONArray size

List of usage examples for org.json.simple JSONArray size

Introduction

In this page you can find the example usage for org.json.simple JSONArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:functionaltests.RestSchedulerTagTest.java

@Test
public void testTaskResultByUnknownTag() throws Exception {
    HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/unknownTag/result");
    JSONArray jsonArray = toJsonArray(response);

    System.out.println(jsonArray.toJSONString());
    assertEquals(0, jsonArray.size());
}

From source file:com.dagobert_engine.trading.service.MtGoxTradeService.java

public List<Order> getOpenOrders() {

    ArrayList<Order> orders = new ArrayList<Order>();

    CurrencyType currency = config.getDefaultCurrency();

    try {// w ww  .j ava  2 s . co m
        String resultJson = adapter.query(MtGoxQueryUtil.create(currency, API_MONEY_ORDERS));

        JSONObject root = (JSONObject) parser.parse(resultJson);
        String result = (String) root.get("result");

        if (!"success".equals(result)) {
            throw new MtGoxException(result);
        }

        JSONArray data = (JSONArray) root.get("data");

        for (int i = 0; i < data.size(); i++) {
            JSONObject orderJson = (JSONObject) data.get(i);

            Order order = new Order();
            order.setOrderId((String) orderJson.get("oid"));
            order.setItem(CurrencyType.valueOf((String) orderJson.get("item")));
            order.setType(Order.OrderType.valueOf(((String) orderJson.get("type")).toUpperCase()));
            order.setAmount(getCurrencyForJsonObj((JSONObject) orderJson.get("amount")));
            order.setEffectiveAmount(getCurrencyForJsonObj((JSONObject) orderJson.get("effective_amount")));
            order.setInvalidAmount(getCurrencyForJsonObj((JSONObject) orderJson.get("invalid_amount")));
            order.setPrice(getCurrencyForJsonObj((JSONObject) orderJson.get("price")));
            order.setStatus(StatusType.valueOf(((String) orderJson.get("status")).toUpperCase()));
            order.setDate(new Date((long) orderJson.get("date") * 1000));
            order.setPriority(Long.parseLong((String) orderJson.get("priority")));

            orders.add(order);

        }
    } catch (Exception exc) {
        throw new MtGoxException(exc);
    }

    return orders;
}

From source file:de.fhg.fokus.odp.portal.datasets.searchresults.BrowseDataSetsSearchResults.java

/**
 * This method reverses a JSONArray./*from  w  w w.  j  av a2  s  .  co m*/
 * 
 * @param comments
 *            the JSONArray to be reversed
 * @return the reversed JSONArray
 */
private JSONArray reverseJSONArray(JSONArray comments) {
    JSONArray toReturn = new JSONArray();
    for (int i = comments.size() - 1; i >= 0; i--) {
        toReturn.add(comments.get(i));
    }
    return toReturn;
}

From source file:functionaltests.RestSchedulerTagTest.java

@Test
public void testJobTagsBadPrefix() throws Exception {
    HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tags/startsWith/blabla");
    JSONArray jsonArray = toJsonArray(response);

    System.out.println(jsonArray.toJSONString());

    assertEquals(0, jsonArray.size());
}

From source file:ActualizadorLocal.Clientes.ClientePasos.java

public void procesarDatos(String datos) throws SQLException {

    datos = "{\"pasos\":" + datos + "}";

    JSONParser parser = new JSONParser();

    try {/*from   w  ww .  j a  va  2 s  .c om*/

        JSONObject obj = (JSONObject) parser.parse(datos);
        JSONArray lista = (JSONArray) obj.get("pasos");
        procesados = lista.size();

        int conta = 1;
        int lotes = procesados / MAX_CACHE_SIZE + 1;

        for (int i = 0; i < lista.size(); i++) {
            if (i % MAX_CACHE_SIZE == 0) {
                _d.primeOUT(label, "Procesado Lote " + conta + " de " + lotes);
                conta++;
            }
            Long a0 = (Long) ((JSONObject) lista.get(i)).get("idNodo");
            String a1 = (String) ((JSONObject) lista.get(i)).get("idDispositivo");
            Long a2 = (Long) ((JSONObject) lista.get(i)).get("tfin");
            Long a3 = (Long) ((JSONObject) lista.get(i)).get("tinicio");

            this.InsertarDatos("\"" + (String) Long.toString(a0) + "\",\"" + a1 + "\",\"" + Long.toString(a2)
                    + "\",\"" + Long.toString(a3) + "\"");

        }

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    syncDB();

}

From source file:com.orthancserver.DicomDecoder.java

private String[] SortSlicesByNumber(OrthancConnection c, JSONArray instances) throws IOException {
    ArrayList<Slice> slices = new ArrayList<Slice>();

    for (int i = 0; i < instances.size(); i++) {
        String uuid = (String) instances.get(i);
        JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid);
        Long index = (Long) instance.get("IndexInSeries");
        slices.add(new Slice((float) index, uuid));
    }//from  www.j  a  va2s  .c o  m

    return SortSlices(slices);
}

From source file:com.wcmc.Software.screens.RegistrationScreen.java

public void setRidersData(String data) {
    try {//from  w  w  w.j a  v a2 s .  co  m
        JSONObject json = (JSONObject) jsonParser.parse(data);
        JSONObject classInfo = (JSONObject) json.get("class");
        if (classInfo != null) {
            classRiders.setTitle(classInfo.get("title").toString());
        }

        classRiders.clear();

        JSONArray riders = (JSONArray) json.get("riders");

        if (riders != null) {
            for (int i = 0; i < riders.size(); i++) {
                JSONObject rider_info = (JSONObject) riders.get(i);
                ClassItem riderItem = new ClassItem();
                riderItem.setText(rider_info.get("name").toString());
                riderItem.setID(Integer.parseInt(rider_info.get("id").toString()));

                riderItem.setY(i * 15);
                riderItem.setWidth(classRiders.getWidth());

                classRiders.add(riderItem);
            }
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:com.acmeair.jmeter.functions.ExtrackBookingInfoFunction.java

private void processJSonString(SampleResult sample) {

    try {//from ww  w . j  av  a  2s .c  o  m
        Object returnObject = new JSONParser().parse(sample.getResponseDataAsString());
        JSONArray jsonArray;
        if (returnObject instanceof JSONArray) {
            jsonArray = (JSONArray) returnObject;
        } else {
            throw new RuntimeException("failed to parse booking information: " + returnObject.toString());
        }
        int bookingNum = jsonArray.size();

        context.setNUMBER_OF_BOOKINGS(bookingNum + "");

        if (bookingNum > 2) {
            context.setNUMBER_TO_CANCEL(bookingNum - 2 + "");
        } else {
            context.setNUMBER_TO_CANCEL("0");
        }
        String[] bookingIds = new String[bookingNum];
        for (int counter = 0; counter < bookingNum; counter++) {
            JSONObject booking = (JSONObject) jsonArray.get(counter);// .pkey.id;
            String bookingId;
            if (ExtractFlightsInfoFunction.pureIDs) {
                bookingId = (String) booking.get("_id");
            } else {
                JSONObject bookingPkey = (JSONObject) booking.get("pkey");
                bookingId = (String) bookingPkey.get("id");
            }
            bookingIds[counter] = bookingId;
        }
        context.setBOOKING_IDs(bookingIds);
        BookingThreadLocal.set(context);

    } catch (ParseException e) {
        System.out.println("responseDataAsString = " + sample.getResponseDataAsString());
        e.printStackTrace();
    } catch (NullPointerException e) {
        System.out.println("NullPointerException in ExtrackBookingInfoFunction - ResponseData ="
                + sample.getResponseDataAsString());
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.gomint.server.network.packet.PacketLogin.java

@Override
public void deserialize(PacketBuffer buffer) {
    this.protocol = buffer.readInt();

    // Decompress inner data (i don't know why you compress inside of a Batched Packet but hey)
    byte[] compressed = new byte[buffer.readInt()];
    buffer.readBytes(compressed);/*w w w . jav  a2 s  .c  o  m*/

    Inflater inflater = new Inflater();
    inflater.setInput(compressed);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    try {
        byte[] comBuffer = new byte[1024];
        while (!inflater.finished()) {
            int read = inflater.inflate(comBuffer);
            bout.write(comBuffer, 0, read);
        }
    } catch (DataFormatException e) {
        System.out.println("Failed to decompress batch packet" + e);
        return;
    }

    // More data please
    ByteBuffer byteBuffer = ByteBuffer.wrap(bout.toByteArray());
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    byte[] stringBuffer = new byte[byteBuffer.getInt()];
    byteBuffer.get(stringBuffer);

    // Decode the json stuff
    try {
        JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(stringBuffer));
        JSONArray chainArray = (JSONArray) jsonObject.get("chain");
        if (chainArray != null) {
            this.validationKey = parseBae64JSON((String) chainArray.get(chainArray.size() - 1)); // First key in chain is last response in chain #brainfuck :D
            for (Object chainObj : chainArray) {
                decodeBase64JSON((String) chainObj);
            }
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // Skin comes next
    this.skin = new byte[byteBuffer.getInt()];
    byteBuffer.get(this.skin);
}

From source file:com.wcmc.Software.screens.RegistrationScreen.java

public void setAutocompleteData(String data) {
    try {/* www.jav a 2  s  . com*/
        riders.clear();
        JSONObject json = (JSONObject) jsonParser.parse(data);
        JSONArray json_riders = (JSONArray) json.get("riders");
        if (json_riders != null) {
            for (int i = 0; i < json_riders.size(); i++) {
                JSONObject rider = (JSONObject) json_riders.get(i);
                System.out.println(rider);
                AutoCompleteItem item = new AutoCompleteItem();
                item.setWidth(400);
                item.setHeight(15);
                item.setText(rider.get("first_name").toString() + " " + rider.get("last_name").toString());
                item.setID(Integer.parseInt(rider.get("id").toString()));
                item.setY((i * 15) + 1);
                riders.add(item);
            }
        }
        showAutocomplete = true;
    } catch (ParseException e) {
        e.printStackTrace();
    }
}