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:control.ProcesoVertimientosServlets.SeleccionarArchivosInformesCargados.java

private void getArchivosCargados(HttpServletRequest request, HttpServletResponse response) {

    try {/* www . j  av  a 2 s  .c om*/

        JSONArray jsonArray = new JSONArray();
        int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso"));

        InformeProcesoSeco manager = new InformeProcesoSeco();

        jsonArray = manager.getArchivosCargados(codigoProceso, null);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        for (Object jsonObject : jsonArray) {

            response.getWriter().write(jsonObject.toString());

        }

    } catch (Exception e) {

    }
}

From source file:com.aerothai.database.building.BuildingService.java

public JSONObject GetBuildingAt(int id) throws Exception {

    Connection dbConn = null;/*from   w w  w  . j ava 2 s  . co  m*/
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "listat");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM building where idbuilding = " + id;
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("idbuilding"));
            jsonData.put("name", rs.getString("name"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;
        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:com.dubture.symfony.core.util.JsonUtils.java

public static JSONArray parseArray(String defaults) {

    try {//from   ww w.j av  a 2s.c om
        return (JSONArray) parser.parse(defaults);
    } catch (Exception e) {
        Logger.logException(e);
        return new JSONArray();
    }
}

From source file:control.ParametrizacionServlets.ActualizarPuntoVertimiento.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  w w  w .  j a  va2s. co m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONObject resError = new JSONObject();
    try {

        //Obtenemos el numero de contrato
        Double contrato = Double.parseDouble(request.getParameter("contrato"));

        //Obtenemos la cadena con la informacion y la convertimos en un
        //JSONArray
        String puntos = request.getParameter("puntos");
        Object obj = JSONValue.parse(puntos);
        JSONArray jsonArray = new JSONArray();
        jsonArray = (JSONArray) obj;

        //Recorremos el JSONArray y obtenemos la informacion.
        for (int i = 0; i < jsonArray.size(); i++) {

            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            String ubicacion = (String) jsonObject.get("ubicacion");
            String latitud = (String) jsonObject.get("latitud");
            String longitud = (String) jsonObject.get("longitud");
            String observacion = (String) jsonObject.get("observacion");
            int estado = Integer.parseInt((String) jsonObject.get("estado"));
            String codigo = (String) jsonObject.get("codigo");
            String tipoEstructura = (String) jsonObject.get("tipoEstructura");

            //Creamos el manager y guardamos la informacion.
            PuntosVertimiento manager = new PuntosVertimiento();
            manager.actualizar(codigo, ubicacion, latitud, longitud, observacion, estado, contrato,
                    tipoEstructura);

        }

        resError.put("error", 1);
    } catch (Exception ex) {
        resError.put("error", 0);

    }

}

From source file:com.bigml.histogram.GroupTarget.java

@Override
@SuppressWarnings("unchecked")
protected void addJSON(JSONArray binJSON, DecimalFormat format) {
    JSONArray targetsJSON = new JSONArray();
    for (Target target : _target) {
        target.addJSON(targetsJSON, format);
    }/*from  ww w .  ja v  a2  s .  c  o m*/
    binJSON.add(targetsJSON);
}

From source file:modelo.ParametrizacionManagers.Consultores.java

public JSONArray getConsultores(String nombre, String apellidos, String direccion, String telefono,
        String telefono2, String identificacion, String correo) throws SQLException {

    JSONArray jsonArray = new JSONArray();
    JSONArray jsonArreglo = new JSONArray();
    JSONObject jsonObject = new JSONObject();

    SeleccionarConsultores seleccionar = new SeleccionarConsultores();
    ResultSet rset = seleccionar.getConsultores(nombre, apellidos, direccion, telefono, telefono2,
            identificacion, correo);// ww w .j  a  v  a  2 s. c o  m

    try {
        while (rset.next()) {

            jsonObject.put("codigo", rset.getString("CODIGO"));
            jsonObject.put("nombre", rset.getString("NOMBRES"));
            jsonObject.put("apellidos", rset.getString("APELLIDOS"));
            jsonObject.put("direccion", rset.getString("DIRECCION"));
            jsonObject.put("telefono1", rset.getString("TELEFONO1"));
            jsonObject.put("telefono2", rset.getString("TELEFONO2"));
            jsonObject.put("correo", rset.getString("EMAIL"));
            jsonObject.put("identificacion", rset.getString("IDENTIFICACION"));
            jsonObject.put("descripcion", rset.getString("NOMBRES") + ' ' + rset.getString("APELLIDOS"));

            jsonArray.add(jsonObject.clone());

        }

    } catch (SQLException ex) {
        // Logger.getLogger(Laboratorios.class.getName()).log(Level.SEVERE, null, ex);
    }

    seleccionar.desconectar();
    jsonArreglo.add(jsonArray);

    return jsonArreglo;
}

From source file:com.yottaa.newrelic.PostJob.java

/**
 *
 *//*from w  ww  . j a va 2s  .c  o  m*/
public void postJobMethod() {

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

    logger.info("Posting Yottaa metrics to New Relic @ " + dateFormat.format(System.currentTimeMillis()));

    ResourceBundle bundle = ResourceBundle.getBundle("yottaa");
    YottaaHttpClientPublic yottaaHttpClientPublic = new YottaaHttpClientPublic(
            bundle.getString("yottaaAPIKey"));

    YottaaHttpClientPartner yottaaHttpClientPartner = new YottaaHttpClientPartner(false);

    // Prepare JSON data that will be posted to New Relic
    JSONObject jsonData = new JSONObject();

    JSONObject agentData = new JSONObject();
    agentData.put("host", "apps.yottaa.com");
    agentData.put("pid", 0);
    agentData.put("version", "1.0.0");

    jsonData.put("agent", agentData);

    JSONArray components = new JSONArray();

    JSONArray sites = yottaaHttpClientPartner.getAccountSites(bundle.getString("yottaaUserId"));

    logger.info("Total number of sites is " + sites.size() + ".");

    for (int i = 0, len = sites.size(); i < len; i++) {
        JSONObject siteObj = (JSONObject) sites.get(i);
        String host = (String) siteObj.get("host");

        logger.info("Retrieve last sample for host " + host + "(" + i + " of " + len + ").");

        JSONObject lastSampleMetrics = yottaaHttpClientPublic.getLastSample(host);

        JSONObject yottaaMetricsObj = new JSONObject();
        yottaaMetricsObj.put("guid", "com.yottaa.Yottaa");
        yottaaMetricsObj.put("duration", 60);
        //yottaaMetricsObj.put("name", host);
        yottaaMetricsObj.put("name", (String) lastSampleMetrics.get("name"));

        JSONObject yottaaMetricsData = new JSONObject();

        // Http Metrics
        if (lastSampleMetrics.get("http_metrics") != null) {
            JSONObject httpMetrics = (JSONObject) lastSampleMetrics.get("http_metrics");

            JSONObject httpMetricsFirstByte = (JSONObject) httpMetrics.get("first_byte");
            JSONObject httpMetricsWait = (JSONObject) httpMetrics.get("wait");
            JSONObject httpMetricsDNS = (JSONObject) httpMetrics.get("dns");
            JSONObject httpMetricsConnect = (JSONObject) httpMetrics.get("connect");

            yottaaMetricsData.put("Component/Http Metrics/Time To First Byte[sec]",
                    Double.parseDouble(httpMetricsFirstByte.get("average").toString()));
            yottaaMetricsData.put("Component/Http Metrics/Waiting Time[sec]",
                    Double.parseDouble(httpMetricsWait.get("average").toString()));
            yottaaMetricsData.put("Component/Http Metrics/DNS Time[sec]",
                    Double.parseDouble(httpMetricsDNS.get("average").toString()));
            yottaaMetricsData.put("Component/Http Metrics/Connection Time[sec]",
                    Double.parseDouble(httpMetricsConnect.get("average").toString()));
        }

        // Issue Metrics
        if (lastSampleMetrics.get("issue_metrics") != null) {
            JSONObject issueMetrics = (JSONObject) lastSampleMetrics.get("issue_metrics");

            yottaaMetricsData.put("Component/Issue Metrics/Critical Error Count[times]",
                    Integer.parseInt(issueMetrics.get("critical_error_count").toString()));
            yottaaMetricsData.put("Component/Issue Metrics/Error Count[times]",
                    Integer.parseInt(issueMetrics.get("error_count").toString()));
            yottaaMetricsData.put("Component/Issue Metrics/Info Count[times]",
                    Integer.parseInt(issueMetrics.get("info_count").toString()));
            yottaaMetricsData.put("Component/Issue Metrics/Warning Count[times]",
                    Integer.parseInt(issueMetrics.get("warning_count").toString()));
        }

        //Webpage Metrics
        if (lastSampleMetrics.get("webpage_metrics") != null) {
            JSONObject webpageMetrics = (JSONObject) lastSampleMetrics.get("webpage_metrics");
            JSONObject webpageMetricsTimeToRender = (JSONObject) webpageMetrics.get("time_to_render");
            JSONObject webpageMetricsTimeToDisplay = (JSONObject) webpageMetrics.get("time_to_display");
            JSONObject webpageMetricsTimeToInteract = (JSONObject) webpageMetrics.get("time_to_interact");

            yottaaMetricsData.put("Component/Webpage Metrics/Time To Render[sec]",
                    Double.parseDouble(webpageMetricsTimeToRender.get("average").toString()));
            yottaaMetricsData.put("Component/Webpage Metrics/Time To Display[sec]",
                    Double.parseDouble(webpageMetricsTimeToDisplay.get("average").toString()));
            yottaaMetricsData.put("Component/Webpage Metrics/Time To Interact[sec]",
                    Double.parseDouble(webpageMetricsTimeToInteract.get("average").toString()));
        }
        yottaaMetricsObj.put("metrics", yottaaMetricsData);

        components.add(yottaaMetricsObj);

        logger.info("Finished Retrieve last sample for host " + host + "(" + i + " of " + len + ").");
    }

    jsonData.put("components", components);

    logger.info("Posted Yottaa Metrics :" + jsonData);

    this.newrelicPost(null, bundle.getString("newrelicLicenseKey"), jsonData);

}

From source file:com.aerothai.database.dept.DeptService.java

public JSONObject GetDeptAt(int id) throws Exception {

    Connection dbConn = null;//from  w w  w.  jav  a  2 s . com
    JSONObject obj = new JSONObject();
    JSONArray objList = new JSONArray();

    int no = 1;
    //obj.put("draw", 2);
    obj.put("tag", "listat");
    obj.put("msg", "error");
    obj.put("status", false);
    try {
        dbConn = DBConnection.createConnection();

        Statement stmt = dbConn.createStatement();
        String query = "SELECT * FROM dept where iddept = " + id;
        System.out.println(query);
        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            JSONObject jsonData = new JSONObject();
            jsonData.put("id", rs.getInt("iddept"));
            jsonData.put("name", rs.getString("name"));
            jsonData.put("shortname", rs.getString("shortname"));
            jsonData.put("no", no);
            objList.add(jsonData);
            no++;
        }
        obj.put("msg", "done");
        obj.put("status", true);
        obj.put("data", objList);
    } catch (SQLException sqle) {
        throw sqle;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        if (dbConn != null) {
            dbConn.close();
        }
        throw e;
    } finally {
        if (dbConn != null) {
            dbConn.close();
        }
    }
    return obj;
}

From source file:modelo.ProcesoVertimientosManagers.VerificacionInfoCaracterizacion.java

public JSONArray getDevolucionCaracterizacion(String codigoPoceso) throws SQLException {

    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();

    SeleccionarVerificacionInfoCaracterizacion select = new SeleccionarVerificacionInfoCaracterizacion();
    ResultSet rset = select.getDevolucionCaracterizacion(codigoPoceso);

    while (rset.next()) {
        jsonObject.put("tipoDevolCaracterizacion", rset.getString(("TIPO_DEVOLUCION")));
        jsonObject.put("fechaEntDevolCaracterizacion", rset.getString(("FECHA_ENTREGA")));
        jsonObject.put("observacionDevolCaracterizacion", rset.getString(("OBSERVACION")));
        jsonObject.put("fechaDevolCaracterizacion", rset.getString(("FECHA_DEVOLUCION")));
    }/*from  w ww.  j  a  va 2s  .com*/

    jsonArray.add(jsonObject.clone());
    return jsonArray;
}

From source file:com.tjackiw.graylog2.plugin.jira.JiraIssue.java

public String toJSONString() {
    JSONObject project = new JSONObject();
    project.put("key", projectKey);

    JSONObject issuetype = new JSONObject();
    issuetype.put("name", issueType);

    JSONObject level = new JSONObject();
    level.put("name", priority);

    JSONArray labelList = new JSONArray();
    String[] labelArr = labels.split("\\,");
    for (String s : labelArr) {
        labelList.add(s);// ww  w.  j a  v a 2s.c om
    }

    JSONArray componentList = new JSONArray();
    String[] compArr = components.split("\\,");
    for (String s : compArr) {
        JSONObject hash = new JSONObject();
        hash.put("name", s);
        componentList.add(hash);
    }

    JSONObject obj = new JSONObject();
    obj.put("summary", title);
    obj.put("description", description);
    obj.put("project", project);
    obj.put("issuetype", issuetype);
    obj.put("labels", labelList);
    obj.put("components", componentList);
    obj.put("priority", level);

    JSONObject fields = new JSONObject();
    fields.put("fields", obj);

    return fields.toJSONString();
}