Example usage for org.json.simple JSONObject JSONObject

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

Introduction

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

Prototype

JSONObject

Source Link

Usage

From source file:com.appzone.sim.services.handlers.PhoneRegistrationServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String phoneNo = request.getParameter(KEY_PHONE_NO);
    // converting to md5
    phoneNo = getMD5(phoneNo);// w ww. j ava 2  s  . co m

    Phone phone = new Phone(phoneNo);

    logger.debug("adding a new phone: {}", phoneNo);
    phoneRepository.add(phone);

    JSONObject json = new JSONObject();
    json.put(JSON_KEY_MD5_PHONE_NO, phoneNo);

    return json.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override// w  ww .ja va  2  s . c om
public JSONObject toJSONObject() {
    final JSONObject result = new JSONObject();
    result.put("flow", flow);
    result.put("tag", tag);
    return result;
}

From source file:com.unilever.audit.services2.ForgetPassword.java

@GET
@Path("Email/{email}")
@Produces("application/json")
public String LoginIn(@PathParam("email") String email) throws IOException {
    boolean status = true;
    String error = null;//w  w w .j a  va 2s  .  c  o m
    JSONObject result = new JSONObject();

    Map<String, Object> hm = new HashMap<String, Object>();
    hm.put("email", email);
    Merchandisers merchidisers = (Merchandisers) merchandisersFacadeREST
            .findOneByQuery("Merchandisers.findByEmail", hm);
    if (merchidisers == null) {
        status = false;
        error = "invalid email";
    } else {
        Properties props = new Properties();
        final String from = "";
        final String password = "";
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.user", from);
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.password", password);
        props.put("mail.smtp.port", "587");
        props.put("mail.smtp.auth", "true");

        Session session = Session.getInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, password);
            }
        });
        session.setDebug(true);
        try {
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom();
            msg.setRecipients(Message.RecipientType.TO, email);
            msg.setSubject("Unilever Confirmation");
            msg.setSentDate(new Date());
            msg.setText("");
            Transport.send(msg);
        } catch (MessagingException ex) {
            //  status = false;
            //  error="Error Sending Email";
            ex.printStackTrace();
        }
    }
    result.put("status", status);
    result.put("error", error);
    System.out.println("----------------" + result.toString());
    return result.toString();
}

From source file:capabilities.Display.java

@Override
public String adaptRole(String dbResult) throws Exception {
    // Variveis retornadas do WURFL em JSON
    int resolution_width;
    int resolution_height;
    int columns;//  w ww. j a  va 2  s. c  o m
    int rows;
    int physical_screen_width;
    int physical_screen_height;
    String dual_orientation;

    // Conversao do JSON de entrada para as variaveis respectivas
    JSONObject capabilities;
    JSONParser parser = new JSONParser();
    capabilities = (JSONObject) parser.parse(dbResult);
    //JSONObject capabilities = (JSONObject) my_obj.get("capabilities");
    System.out.println("\t" + capabilities);

    resolution_width = Integer.parseInt((String) capabilities.get("resolution_width"));
    resolution_height = Integer.parseInt((String) capabilities.get("resolution_height"));
    columns = Integer.parseInt((String) capabilities.get("columns"));
    rows = Integer.parseInt((String) capabilities.get("rows"));
    physical_screen_width = Integer.parseInt((String) capabilities.get("physical_screen_width"));
    physical_screen_height = Integer.parseInt((String) capabilities.get("physical_screen_height"));
    dual_orientation = (String) capabilities.get("dual_orientation");

    // Criar um novo JSON e adicionar as informaes  ele.
    JSONObject virtual = new JSONObject();

    if (physical_screen_width < physical_screen_height) {
        virtual.put("orientation_preferred", "portrait");
        virtual.put("thumbs_only", "true");
    } else {
        virtual.put("orientation_preferred", "landscape");
        virtual.put("thumbs_only", "false");
    }

    // Clculo da dimenso em polegadas da diagonal do dispositivo
    double diagonal = Math.sqrt(
            physical_screen_width * physical_screen_width + physical_screen_height * physical_screen_height);
    diagonal *= 0.039370;

    if (diagonal < 4) {
        virtual.put("average_size", "small_dispositive");
    } else if (diagonal > 5.5) {
        virtual.put("average_size", "large_dispositive");
    } else {
        virtual.put("average_size", "medium_dispositive");
    }

    // Adicionar esse novo JSON ao JSON de entrada e retorn-lo
    capabilities.put("virtual", virtual);
    return capabilities.toJSONString();
}

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

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        String servicio = request.getRequestURI().replace("/HCEMed/ExamenFisico/", "");
        switch (servicio) {
        case "guardar":
            guardarExamenFisico(request).writeJSONString(out);
            break;

        case "traerUltimo":
            traerUltimoExamenFisico(request).writeJSONString(out);
            break;

        case "traerFecha":
            traerExamenFisicoFecha(request).writeJSONString(out);
            break;

        default://from   www  .  jav  a2  s  .  c om
            obj = new JSONObject();
            objArray = new JSONArray();
            obj.put("error", "404 - El servicio " + servicio + " no existe");
            objArray.add(obj);
            objArray.writeJSONString(out);
            break;
        }

    }
}

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

@SuppressWarnings("unchecked")
private JSONObject newDataCell(double value) {
    JSONObject cell = new JSONObject();
    cell.put("v", value);
    return cell;/*from ww  w  . j av  a2s .c om*/
}

From source file:JavaCloud.Models.VM.java

public void reset() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("token", token);
    object.put("vm_id", id);
    Utils.request(address, "/api/vm/reset/", object);
}

From source file:com.opensoc.enrichment.adapters.cif.CIFHbaseAdapter.java

public JSONObject enrich(String metadata) {

    JSONObject output = new JSONObject();
    LOGGER.debug("=======Looking Up For:" + metadata);
    output.putAll(getCIFObject(metadata));

    return output;
}

From source file:modelo.ProcesoVertimientosManagers.ProcesoVertimientos.java

/**
  * /*from  w  w w.java 2s  .  com*/
  * Llama al delegate para obtener los clientes.
  * 
  * @param codigoProceso
  * @param nit
  * @param ciiu
  * @param contrato
  * @param razonSocial
  * @param anio
  * @param fechaInicial
  * @param fechaFinal
  * @param filaInicio
  * @param filaFin
  * @return
  * @throws Exception 
  */
public JSONArray getProcesoVertimientos(String codigoProceso, String nit, String contrato, String ciiu,
        String razonSocial, String anio, String fechaInicial, String fechaFinal, String filaInicio,
        String filaFin) throws Exception {

    //Ejecutamos la consulta y obtenemos el ResultSet
    SeleccionarProcesoVertimientos select = new SeleccionarProcesoVertimientos(codigoProceso, nit, contrato,
            ciiu, razonSocial, anio, fechaInicial, fechaFinal, filaInicio, filaFin);
    ResultSet rset = select.ejecutar();

    //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("codigoProceso", rset.getString("CODIGO"));
        jsonObject.put("nit", rset.getString("NIT"));
        jsonObject.put("razonSocial", rset.getString("RAZON_SOCIAL"));
        jsonObject.put("actividadEconomica", rset.getString("CIIU"));
        jsonObject.put("contrato", rset.getString("FK_CONTRATO"));
        jsonObject.put("tipoInforme", rset.getString("TIPOINFORME"));
        jsonObject.put("fechaProceso", rset.getString("FECHA_PROCESO"));
        jsonObject.put("estado", rset.getString("ESTADOP"));
        jsonObject.put("rnum", rset.getString("RNUM"));
        jsonObject.put("valRQ", rset.getString("VALIDAR_RQ"));

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

    }

    jsonArreglo.add(jsonArray);

    //Se cierra el ResultSet
    select.desconectar();

    return jsonArreglo;

}

From source file:com.oic.utils.TestValiadtion.java

public void testBirthday() {
    JSONObject json = new JSONObject();
    json.put("birthday", "2001-01-01");
    Validators v = new Validators(json);
    v.add("birthday", v.birthday());
    assertTrue(v.validate());/*from  w  ww.j  a  v a  2 s.  c  om*/
}