Example usage for org.json.simple JSONArray JSONArray

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

Introduction

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

Prototype

JSONArray

Source Link

Usage

From source file:com.dubture.twig.core.model.TwigCallable.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public void addArgs(List arguments) {

    JSONArray args = new JSONArray();

    for (Object o : arguments) {

        FormalParameter param = (FormalParameter) o;

        if (param == null)
            continue;

        JSONObject arg = new JSONObject();
        ASTNode init = param.getInitialization();

        String defaultValue = init != null ? init.getClass().toString() : "";

        if (init instanceof Scalar) {
            Scalar scalar = (Scalar) init;
            defaultValue = scalar.getValue();

        }//from www .ja va 2  s.  c om

        this.arguments.put(param.getName(), defaultValue);
        arg.put(param.getName(), defaultValue);
        args.add(arg);

    }

    filterArguments = args;

}

From source file:com.conwet.silbops.msg.UnadvertiseMsg.java

@Override
@SuppressWarnings("unchecked")
public JSONObject getPayloadAsJSON() {

    JSONObject json = new JSONObject();
    json.put("advertise", advertise.toJSON());
    json.put("context", context.toJSON());

    JSONArray uncov = new JSONArray();
    for (Advertise fil : uncovered) {

        uncov.add(fil.toJSON());//from  w  w  w . java2s  . c o m
    }
    json.put("uncovered", uncov);

    return json;
}

From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONHistogramOutputSerializer.java

private JSONObject toJSON(long timestamp, Points.Point point, String unit) throws SerializationException {
    final JSONObject object = new JSONObject();
    object.put("timestamp", timestamp);

    if (!(point.getData() instanceof HistogramRollup)) {
        throw new SerializationException("Unsupported type. HistogramRollup expected.");
    }//from  w  w  w. j  ava2 s .c o m

    HistogramRollup histogramRollup = (HistogramRollup) point.getData();

    final JSONArray hist = new JSONArray();
    for (Bin<SimpleTarget> bin : histogramRollup.getBins()) {
        final JSONObject obj = new JSONObject();
        obj.put("mean", bin.getMean());
        obj.put("count", bin.getCount());
        hist.add(obj);
    }
    object.put("histogram", hist);

    return object;
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void leerMultiplesConvocatorias(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<ConvocatoriaEntity> convocatorias = new ArrayList<>();
    convocatorias = CtrlUsuario.leerMultiplesConvocatorias(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2"))); // tamao y posicin

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (ConvocatoriaEntity convocatoria : convocatorias) {
        JSONObject obj = new JSONObject();
        obj.put("id", convocatoria.getIdConvocatoria());
        obj.put("titulo", convocatoria.getNombre());
        list1.add(obj);//from   www. j  a va 2s  .co m
    }
    out.print(list1);
}

From source file:com.saludtec.web.PagosWeb.java

private JSONArray guardarPago(HttpServletRequest request) {
    Pagos pago = new Pagos();
    PlanesDeTratamiento planTratamiento = ejbPlanesDeTratamiento
            .traer(Integer.parseInt(request.getParameter("idPlanTratamiento")));
    pago.setValorPago(request.getParameter("valorPago"));
    pago.setFechaPago(request.getParameter("fechaPago"));
    pago.setIdPlanTratamiento(planTratamiento);
    pago.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS
    pago = ejbPagos.crear(pago);/*w w  w .  ja v  a2 s.  co  m*/
    obj = new JSONObject();
    objArray = new JSONArray();
    if (pago != null) {
        obj.put("idPago", pago.getIdPago());
        objArray.add(obj);
    } else {
        obj.put("error", "no se pudo guardar el pago");
        objArray.add(obj);
    }
    return objArray;
}

From source file:modelo.ParametrizacionManagers.Tarifas.java

/**
  * /*from  w ww  . j  a v a2  s  .  co m*/
  * Obtiene la informacion de una unidad de medida y
  * guarda todo en un JSONArray para entregarselo a la vista.
  * 
  * @return JSONArray
  * @throws SQLException 
  */
public JSONArray getTarifa(int codigo) throws SQLException {

    //Ejecutamos la consulta y obtenemos el ResultSet
    SeleccionarTarifas select = new SeleccionarTarifas();
    ResultSet rset = select.getTarifa(codigo);

    //Creamos los JSONArray para guardar los objetos JSON
    JSONArray jsonArray = new JSONArray();

    //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos
    //en el JSONArray.
    while (rset.next()) {
        JSONObject jsonObject = new JSONObject();
        //Armamos el objeto JSON con la informacion del registro
        jsonObject.put("codigo", rset.getString("CODIGO"));
        jsonObject.put("valor", rset.getString("VALOR"));
        jsonObject.put("codParm", rset.getString("FK_PARAMFISICOQUIMICO"));
        jsonObject.put("descpParm", rset.getString("DESPARM"));

        //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista.
        jsonArray.add(jsonObject.clone());

    }

    select.desconectar();
    return jsonArray;

}

From source file:ab.server.Proxy.java

@SuppressWarnings("unchecked")
public synchronized <T> T send(ProxyMessage<T> message) {
    //Long t1 = System.nanoTime();
    JSONArray a = new JSONArray();
    a.add(id);/*from www  .j av  a 2  s.c o m*/
    a.add(message.getMessageName());
    a.add(message.getJSON());

    ProxyResult<T> result = new ProxyResult<T>();
    result.message = message;
    results.put(id, result);

    for (WebSocket conn : connections()) {
        conn.send(a.toJSONString());
    }

    id++;

    try {

        return (T) result.queue.take();
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    return null;
}

From source file:JSONParser.JSONOperations.java

public JSONArray getRowsFromSupportapiJSON(JSONObject responseObject, String rowName) {
    loggerObj.log(Level.INFO, "Inside getRowsFromSupportapiJSON method");
    JSONObject response = (JSONObject) responseObject.get("response");
    JSONObject result = (JSONObject) response.get("result");
    JSONObject cases = (JSONObject) result.get("Cases");
    JSONArray row = new JSONArray();

    Object rowObj = cases.get(rowName);

    if (rowObj instanceof JSONObject) {
        loggerObj.log(Level.INFO, "JSONResponse is JSONObject");
        row.add(rowObj);/*from ww  w.ja  v  a2 s  .  c  om*/
    } else if (rowObj instanceof JSONArray) {
        loggerObj.log(Level.INFO, "JSONResponse is JSONArray");
        row = (JSONArray) rowObj;
    }

    loggerObj.log(Level.INFO, "successfully returning row from getRowsFromSupportapiJSON method");
    return row;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.DomainObjectJSONSerializer.java

private static JSONArray serializeRelation(Set<? extends AbstractDomainObject> roleSet) {
    JSONArray jsonList = new JSONArray();
    for (AbstractDomainObject obj : roleSet) {
        jsonList.add(obj.getExternalId());
    }/*from   w w  w . j  a v a  2  s  . c om*/
    return jsonList;
}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONArray generateRows() {
    // figure out the entire time series
    ArrayList<Long> timeSeries = new ArrayList<Long>();
    for (Metric metric : metrics) {
        for (TagsArray t : metric.timeSeries.keySet()) {
            timeSeries = TimeSeries.merge(timeSeries, metric.timeSeries.get(t));
        }//w ww . j av  a  2  s  .  c  o m
    }
    JSONObject nullCell = new JSONObject();
    JSONArray rows = new JSONArray();
    for (long ts : timeSeries) {
        JSONObject row = new JSONObject();
        JSONArray cells = new JSONArray();
        cells.add(newTsCell(ts));
        for (Metric metric : metrics) {
            for (TagsArray t : metric.timeSeries.keySet()) {
                ArrayList<DataPoint> points = metric.timeSeries.get(t);
                if (points.size() > 0 && points.get(0).ts == ts) {
                    cells.add(newDataCell(points.get(0).value));
                    points.remove(0);
                } else {
                    cells.add(nullCell);
                }
            }
        }
        row.put("c", cells);
        rows.add(row);
    }
    return rows;
}