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:control.ParametrizacionServlets.EliminarActParamfisicoquimicos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//  w  ww  . j ava2 s . 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(); // uno significa que no hay error
    try {
        int codigoAct = Integer.parseInt(request.getParameter("actividad"));
        int codigoParam = Integer.parseInt(request.getParameter("parametro"));

        //Obtenemos La informacion del manager
        ActParamFisicoquimicos manager = new ActParamFisicoquimicos();
        //Almacenamos el error que pueda resultar
        respError = manager.Eliminar(codigoAct, codigoParam);

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

    } catch (Exception ex) {
        respError.put("error", 0);
        response.setContentType("application/json");
        response.getWriter().write(respError.toString());
    }

}

From source file:workspace.java

private JSONArray getJsonArrayFromStringArray(String[] a, String[] b) {
    JSONObject[] obj = new JSONObject[a.length];
    JSONArray ja = new JSONArray();
    for (int i = 0; i < a.length; i++) {
        obj[i] = new JSONObject();
        obj[i].put("pa", b[i]);
        obj[i].put("stud", a[i]);
        ja.add(obj[i]);// w w w.j a va2  s. c o m
    }
    return ja;
}

From source file:com.imagelake.earnings.Servlet_EarningsValues.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from w w  w  . java2  s.co  m*/
        String uid = request.getParameter("uid");
        if (uid != null && !uid.equals("")) {

            uidd = Integer.parseInt(uid);

            PaymentPreferences pp = ppimp.getPendingEarning(uidd, 1);
            double pd = 00.00;
            double ad = 00.00;
            if (pp != null) {
                pd = pp.getAmount();
                DecimalFormat df1 = new DecimalFormat("#.##");
                pd = Double.valueOf(df1.format(pd));

            }

            SellerIncome sin = sidi.getSellerIncome(uidd);
            ad = sin.getTotal();
            DecimalFormat df = new DecimalFormat("#.##");
            ad = Double.valueOf(df.format(ad));

            double netamo = ad - pd;
            DecimalFormat df2 = new DecimalFormat("#.##");
            netamo = Double.valueOf(df2.format(netamo));

            JSONObject jo = new JSONObject();
            jo.put("pe", pd);
            jo.put("ab", ad);
            jo.put("ne", netamo);

            out.write("json=" + jo.toJSONString());
        }
    } catch (Exception e) {
        e.printStackTrace();

    }
}

From source file:com.mobicage.rogerthat.form.UnicodeListWidgetResult.java

@SuppressWarnings("unchecked")
@Override//  w ww  . j  av a 2  s  .  co  m
public JSONObject toJSONObject() {
    JSONObject obj = new JSONObject();
    if (this.values == null)
        obj.put("values", null);
    else {
        JSONArray array = new JSONArray();
        for (String val : this.values) {
            array.add(val);
        }
        obj.put("values", array);
    }
    return obj;
}

From source file:io.personium.client.RelationManager.java

/**
 * This method performs create operation using Relation object.
 * @param obj Relation object//  ww  w. j av  a2  s  .co m
 * @return Relation object that is created
 * @throws DaoException Exception thrown
 */
@SuppressWarnings("unchecked")
public Relation create(Relation obj) throws DaoException {
    JSONObject body = new JSONObject();
    body.put("Name", obj.getName());
    body.put("_Box.Name", obj.getBoxName());
    JSONObject json = internalCreate(body);
    obj.initialize(this.accessor, json);
    return obj;
}