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.saludtec.web.GaleriaWeb.java

private JSONArray guardarGaleria(HttpServletRequest request) {
    Galeria galeria = new Galeria();
    Pacientes paciente = new Pacientes();
    paciente.setIdPaciente(Integer.parseInt(request.getParameter("idPaciente")));
    galeria.setIdPaciente(paciente);//ww  w .  j av  a2s.com
    galeria.setFoto(request.getParameter("foto"));
    galeria.setFecha(request.getParameter("fecha"));
    galeria.setHora(request.getParameter("hora"));
    galeria.setIdUsuario(Integer.parseInt(request.getSession().getAttribute("usuario").toString()));//RECORDAR QUE ESTE VALOR ESTA QUEMADO Y HAY QUE CAMBIARLO CUANDO SE CREE LA TABLA USUARIOS
    galeria = ejbGaleria.crear(galeria);
    obj = new JSONObject();
    objArray = new JSONArray();
    if (galeria != null) {
        obj.put("idFoto", galeria.getIdFoto());
        objArray.add(obj);
    } else {
        obj.put("error", "no se pudo guardar la foto");
        objArray.add(obj);
    }
    return objArray;
}

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

private JSONArray listarVinculacion() throws NonexistentEntityException {
    List<TiposVinculacion> tiposVinculacion = ejb.traerTiposVinculacion();
    objArray = new JSONArray();
    for (TiposVinculacion tipoVinculacion : tiposVinculacion) {
        obj = new JSONObject();
        obj.put("idTipoVinculacion", tipoVinculacion.getIdTipoVinculacion());
        obj.put("tipoVinculacion", tipoVinculacion.getTipoVinculacion());
        objArray.add(obj);//  w  w  w  .j a  v  a 2s .  com
    }
    return objArray;
}

From source file:com.dbay.apns4j.model.Payload.java

@SuppressWarnings("unchecked")
@Override//from  w  ww . ja va 2 s  .  c  om
public String toString() {
    JSONObject object = new JSONObject();
    JSONObject apsObj = new JSONObject();
    if (getAlert() != null) {
        apsObj.put("alert", getAlert());
    } else {
        if (getAlertBody() != null || getAlertLocKey() != null) {
            JSONObject alertObj = new JSONObject();
            putIntoJson("body", getAlertBody(), alertObj);
            putIntoJson("action-loc-key", getAlertActionLocKey(), alertObj);
            putIntoJson("loc-key", getAlertLocKey(), alertObj);
            putIntoJson("launch-image", getAlertLaunchImage(), alertObj);
            if (getAlertLocArgs() != null) {
                JSONArray array = new JSONArray();
                for (String str : getAlertLocArgs()) {
                    array.add(str);
                }
                alertObj.put("loc-args", array);
            }
            apsObj.put("alert", alertObj);
        }
    }

    if (getBadge() != null) {
        apsObj.put("badge", getBadge().intValue());
    }
    putIntoJson("sound", getSound(), apsObj);

    if (getContentAvailable() != null) {
        apsObj.put("content-available", getContentAvailable().intValue());
    }

    object.put(APS, apsObj);
    if (getParams() != null) {
        for (Entry<String, Object> e : getParams().entrySet()) {
            object.put(e.getKey(), e.getValue());
        }
    }
    return object.toString();
}

From source file:edu.iu.incntre.flowscale.util.JSONConverter.java

public static JSONArray toPortStat(List<OFStatistics> ofs) {
    JSONArray jsonArray = new JSONArray();

    for (OFStatistics ofst : ofs) {

        OFPortStatisticsReply st = (OFPortStatisticsReply) ofst;

        JSONObject jsonObject = new JSONObject();
        if (st.getPortNumber() < -2) {
            continue;
        }//  w  w w . j  a  v  a  2  s . c  om
        jsonObject.put("port_id", st.getPortNumber());
        jsonObject.put("receive_packets", st.getreceivePackets());
        jsonObject.put("transmit_packets", st.getTransmitPackets());
        jsonObject.put("receive_bytes", st.getReceiveBytes());
        jsonObject.put("transmit_bytes", st.getTransmitBytes());

        jsonArray.add(jsonObject);

    }

    return jsonArray;

}

From source file:luceneprueba.Reader.java

public void searchOnIndex(String wordQuery, String date) {
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser("review", analyzer);
    Query query;// w  w w  .  ja v  a  2  s  .co m
    try {
        query = parser.parse("date: \"+" + date + "\" AND " + cleanInput(wordQuery));
        ScoreDoc[] hits = indexSearcher.search(query, 60).scoreDocs;

        if (hits.length == 0) {
            //System.out.println("[Search] No se han encontrado coincidencias.");
        } else {
            //System.out.println("[Search] Se han encontrado: " + hits.length + " coincidencias.");
            JSONArray reviews = new JSONArray();
            for (ScoreDoc hit : hits) {
                Document hitDoc = indexSearcher.doc(hit.doc);
                //System.out.println(i+".- Score: " + hit.score + ", Doc: " + hitDoc.get("movieId") + ", path: " + hitDoc.get("path") + ", Tile review: " + hitDoc.get("title"));
                JSONObject json = new JSONObject();
                json.put("date", hitDoc.get("date"));
                json.put("genre", hitDoc.get("genre"));
                json.put("review", hitDoc.get("review"));
                json.put("score", hitDoc.get("score"));
                reviews.add(json);
            }
            try (FileWriter file = new FileWriter(
                    "files/output/top-k/reviews_" + date.replace(" ", "") + ".json")) {
                file.write(reviews.toJSONString());
                file.flush();
                //indexReader.close();
            }
        }

    } catch (ParseException | IOException ex) {
        Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
        for (StackTraceElement st : ex.getStackTrace()) {
            System.out.println(st.toString());
        }
        System.out.println(ex.getLocalizedMessage());
    }

}

From source file:edu.ucsd.library.xdre.web.MarcModsImportController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String ds = request.getParameter("ts");
    String collectionId = request.getParameter("category");
    String unit = request.getParameter("unit");
    String reset = request.getParameter("reset");
    String message = request.getParameter("message");
    String fileStore = request.getParameter("fs");
    String source = request.getParameter("source");
    String bibNumber = request.getParameter("bib");
    String modsXml = request.getParameter("mods");
    String copyrightStatus = request.getParameter("copyrightStatus");
    String copyrightJurisdiction = request.getParameter("copyrightJurisdiction");
    String copyrightOwner = request.getParameter("copyrightOwner");
    String program = request.getParameter("program");
    String accessOverride = request.getParameter("accessOverride");
    String licenseBeginDate = request.getParameter("licenseBeginDate");
    String licenseEndDate = request.getParameter("licenseEndDate");

    HttpSession session = request.getSession();
    DAMSClient damsClient = null;/*from  w ww  .ja  v a2s .  c  om*/
    Map dataMap = new HashMap();
    try {
        if (ds == null)
            ds = Constants.DEFAULT_TRIPLESTORE;

        damsClient = new DAMSClient(Constants.DAMS_STORAGE_URL);
        damsClient.setTripleStore(ds);

        Map<String, String> collectionMap = damsClient.listCollections();
        Map<String, String> unitsMap = damsClient.listUnits();
        List<String> tsSrcs = damsClient.listTripleStores();
        List<String> fsSrcs = damsClient.listFileStores();
        String fsDefault = damsClient.defaultFilestore();
        if (fileStore == null || fileStore.length() == 0)
            fileStore = fsDefault;

        message = (!StringUtils.isBlank(message) || StringUtils.isBlank(collectionId)) ? message
                : (String) request.getSession().getAttribute("message");
        request.getSession().removeAttribute("message");

        JSONArray accessValues = new JSONArray();
        accessValues.addAll(Arrays.asList(RecordUtil.ACCESS_VALUES));

        Map<String, String> countryCodes = getCountryCodes(request);

        dataMap.put("categories", collectionMap);
        dataMap.put("category", collectionId);
        dataMap.put("units", unitsMap);
        dataMap.put("unit", unit);
        dataMap.put("message", message);
        dataMap.put("triplestore", ds);
        dataMap.put("triplestores", tsSrcs);
        dataMap.put("filestores", fsSrcs);
        dataMap.put("filestore", fileStore);
        dataMap.put("filestoreDefault", fsDefault);
        dataMap.put("copyrightStatus", RecordUtil.COPYRIGHT_VALUES);
        dataMap.put("program", RecordUtil.PROGRAM_VALUES);
        dataMap.put("accessOverride", accessValues);
        dataMap.put("licenseBeginDate", licenseBeginDate);
        dataMap.put("licenseEndDate", licenseEndDate);
        dataMap.put("countryCodes", countryCodes);

    } catch (Exception e) {
        e.printStackTrace();
        message += e.getMessage();
    } finally {
        if (damsClient != null)
            damsClient.close();
    }
    return new ModelAndView("marcModsImport", "model", dataMap);
}

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

private JSONArray listarDocumentos() throws NonexistentEntityException {
    List<TiposDocumentos> tiposDocumentos = ejb.traerTiposDocumentos();
    objArray = new JSONArray();
    for (TiposDocumentos tipoDocumento : tiposDocumentos) {
        obj = new JSONObject();
        obj.put("idTipoDocumento", tipoDocumento.getIdTipoDocumento());
        obj.put("tipoDocumento", tipoDocumento.getTipoDocumento());
        objArray.add(obj);/*from  w  ww.  j  a v a 2 s .  c o  m*/
    }
    return objArray;
}

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

private JSONArray listarPago(HttpServletRequest request) {
    List<Pagos> pagos = ejbPagos.listar(Integer.parseInt(request.getParameter("idPlanTratamiento")));
    objArray = new JSONArray();
    if (pagos != null) {
        for (Pagos pago : pagos) {
            obj = new JSONObject();
            obj.put("idPago", pago.getIdPago());
            obj.put("valorPago", pago.getValorPago());
            obj.put("fechaPago", pago.getFechaPago());
            obj.put("idPlanTratamiento", pago.getIdPlanTratamiento().getIdPlanDeTratamiento());
            objArray.add(obj);//w w w  . j  a v  a 2s .c o  m
        }
    }
    return objArray;
}

From source file:modelo.ParametrizacionManagers.DocumentacionRequerida.java

/**
 * /*from   w ww  . jav a  2  s .  c om*/
 * Obtiene la informacion de la documentacion requerida y
 * guarda todo en un JSONArray para entregarselo a la vista.
 * 
 * @return JSONArray
 * @throws SQLException 
 */
public JSONArray getDocumentacionRequerida(String descripcion, String tipoInforme) throws SQLException {

    //Ejecutamos la consulta y obtenemos el ResultSet
    SeleccionarDocumentacionRequerida select = new SeleccionarDocumentacionRequerida();
    ResultSet rset = select.getDocumentacionRequeridas(descripcion, tipoInforme);

    //Creamos los JSONArray para guardar los objetos JSON
    JSONArray jsonArray = new JSONArray();
    JSONArray jsonArreglo = new JSONArray();
    //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos
    //en el JSONArray.
    while (rset.next()) {

        //Armamos el objeto JSON con la informacion del registro
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("codigo", rset.getString("CODIGO"));
        jsonObject.put("descripcion", rset.getString("DESCRIPCION"));
        jsonObject.put("tipoInforme", rset.getString("TIPO_INFORME"));
        jsonObject.put("codTipoInforme", rset.getString("COD_TIPO_INFORME"));

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

    }

    jsonArreglo.add(jsonArray);
    select.desconectar();
    return jsonArreglo;

}

From source file:com.mobicage.rogerthat.SearchConfig.java

@SuppressWarnings("unchecked")
@Override/*from   w w w  .  j a  v  a  2s. c  om*/
public JSONObject toJSONObject() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("enabled", enabled);
    jsonObject.put("keywords", keywords);
    JSONArray jsonArray = new JSONArray();
    for (SearchLocation l : locations) {
        jsonArray.add(l.toJSONObject());
    }
    jsonObject.put("locations", jsonArray);
    return jsonObject;
}