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:modelo.UsuariosManagers.Usuarios.java

/**
 * /*ww  w  . java  2  s  .c  o m*/
 * Llama al delegate para Eliminar una actividad economica.
 * 
 * @param codigo     
 * @throws Exception 
 */
public JSONObject Eliminar(int codigo) throws Exception {

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

    Integer respError;

    EliminarUsuario delete = new EliminarUsuario(codigo);
    delete.ejecutar();

    respError = delete.getError();

    jsonObject.put("error", respError);

    return jsonObject;

}

From source file:JavaCloud.Models.VM.java

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

From source file:control.ParametrizacionServlets.ActualizarUnidadesMedida.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  w w w .  ja  v  a 2 s. 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 respError = new JSONObject();
    try {

        //Obtenemos la informacion del form.
        int codigo = Integer.parseInt(request.getParameter("codigo"));
        String descripcion = request.getParameter("descripcion");

        UnidadesMedida manager = new UnidadesMedida();
        respError = manager.actualizar(codigo, descripcion);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(respError.toString());

    } catch (Exception ex) {
        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        respError.put("error", 0);
        response.getWriter().write(respError.toString());

    }

}

From source file:com.conwet.silbops.model.ContextFunctionTest.java

@Test
@SuppressWarnings({ "unchecked" })
public void shouldJSONize() {

    JSONObject key1 = new JSONObject();
    key1.put("notAttr", "pub1:double");
    key1.put("subscriptionAttr", "sub1:double");

    JSONObject json = new JSONObject();
    json.put(key1.toJSONString(), 10.0D);

    assertThat(function.toJSONString()).isEqualTo(json.toJSONString());
    assertThat(ContextFunction.fromJSON(json)).isEqualTo(function);
}

From source file:com.saludtec.web.DiagnosticosWeb.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/Diagnosticos/", "");
        switch (servicio) {
        case "guardar":
            guardarEvolucionComentario(request).writeJSONString(out);
            break;

        case "listar":
            listarEvolucionComentario(request).writeJSONString(out);
            break;

        default://  w  w  w.  ja  v  a2  s  .  co m
            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.appzone.sim.services.handlers.AbstractServiceHandler.java

@Override
public String serve(HttpServletRequest request) {

    logger.debug("start serving request");
    if (keywordMatcher.match(request)) {
        return doProcess(request);
    } else {/*from  www  .  ja  va2s. c  om*/

        if (nextServiceHandler != null) {
            return nextServiceHandler.serve(request);
        } else {
            logger.debug("cannot find any Handler to serve");
            JSONObject json = new JSONObject();
            json.put("error", "no handler found");

            return json.toJSONString();
        }

    }
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.ClustersToJson.java

public static JSONArray hashToJSONArrayRepresentationBinaryTree(String id, String hash, Jedis jedis, String id2,
        String hash2) {/*from  w w  w . ja  v a  2 s.  c om*/
    JSONArray result = new JSONArray();
    JSONObject info;
    Map<String, String> attr_cluster = jedis.hgetAll(hash);
    String cluster_name = attr_cluster.get("cluster_ids_name");
    if (!cluster_name.equals("cluster_splited")) {
        info = new JSONObject();
        info.put("name", "Centroid " + id);
        String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id).toArray(new String[0]);
        info.put("children", fullestoArray(instance_group_keys, jedis));
    } else {
        String id_left_centroid = attr_cluster.get("id_left_centroid");
        String id_right_centroid = attr_cluster.get("id_right_centroid");

        String hash_left = attr_cluster.get("hash_left");
        String hash_right = attr_cluster.get("hash_right");

        info = new JSONObject();
        info.put("name", "Centroid " + id);
        info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis,
                id_right_centroid, hash_right));
    }
    result.add(info);

    attr_cluster = jedis.hgetAll(hash2);
    cluster_name = attr_cluster.get("cluster_ids_name");

    if (!cluster_name.equals("cluster_splited")) {
        info = new JSONObject();
        info.put("name", "Centroid " + id2);

        String[] instance_group_keys = jedis.keys("Instances_centroid_ID_" + id2).toArray(new String[0]);
        info.put("children", fullestoArray(instance_group_keys, jedis));
    } else {
        String id_left_centroid = attr_cluster.get("id_left_centroid");
        String id_right_centroid = attr_cluster.get("id_right_centroid");

        String hash_left = attr_cluster.get("hash_left");
        String hash_right = attr_cluster.get("hash_right");

        info = new JSONObject();
        info.put("name", "Centroid " + id2);
        info.put("children", hashToJSONArrayRepresentationBinaryTree(id_left_centroid, hash_left, jedis,
                id_right_centroid, hash_right));
    }
    result.add(info);
    return result;
}

From source file:control.ParametrizacionServlets.InsertarActParamFisicoquimicos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from w w w .  ja  v a 2s  .c o 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 respError = new JSONObject();

    try {

        //Obtenemos los datos enviados.
        String mayorInicial = request.getParameter("mayorInicial");
        String mayorFinal = request.getParameter("mayorFinal");
        Double rangoFinal = Double.parseDouble(request.getParameter("rangoFinal"));
        Double rangoInicial = Double.parseDouble(request.getParameter("rangoInicial"));
        Integer parametro = Integer.parseInt(request.getParameter("parametro"));
        Integer actividad = Integer.parseInt(request.getParameter("actividad"));
        String mostrarRango = request.getParameter("mostrarRango");

        //Creamos el manager para registrar la informacion
        ActParamFisicoquimicos manager = new ActParamFisicoquimicos();

        respError = manager.insertar(actividad, parametro, rangoInicial, rangoFinal, mayorInicial, mayorFinal,
                mostrarRango);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(respError.toString());

    } catch (Exception ex) {
        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        respError.put("error", 0);
        response.getWriter().write(respError.toString());
    }

}

From source file:control.ParametrizacionServlets.ActualizarActParamfisicoquimicos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*  w w  w.  ja  v  a  2  s  . 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 respError = new JSONObject();
    try {
        String mayorInicial = request.getParameter("mayorInicial");
        String mayorFinal = request.getParameter("mayorFinal");
        Double rangoFinal = Double.parseDouble(request.getParameter("rangoFinal"));
        Double rangoInicial = Double.parseDouble(request.getParameter("rangoInicial"));
        Integer parametro = Integer.parseInt(request.getParameter("parametro"));
        Integer actividad = Integer.parseInt(request.getParameter("actividad"));
        int codigo = Integer.parseInt(request.getParameter("codigo"));
        String mostrarRango = request.getParameter("mostrarRango");

        //Creamos el manager para registrar la informacion
        ActParamFisicoquimicos manager = new ActParamFisicoquimicos();

        respError = manager.actualizar(codigo, actividad, parametro, rangoInicial, rangoFinal, mayorInicial,
                mayorFinal, mostrarRango);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(respError.toString());

    } catch (Exception ex) {
        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        respError.put("error", 0);
        response.getWriter().write(respError.toString());
    }

}

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

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

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

    return json;/*from  w ww . jav a  2 s . c  om*/
}