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:be.fedict.eid.applet.service.JSONServlet.java

public static void outputJSON(EIdData eIdData, PrintWriter writer)
        throws IOException, CertificateEncodingException {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");

    JSONObject eidJSONObject = new JSONObject();

    JSONObject identityJSONObject = new JSONObject();
    eidJSONObject.put("identity", identityJSONObject);
    Identity identity = eIdData.identity;
    identityJSONObject.put("nationalNumber", identity.nationalNumber);
    identityJSONObject.put("name", identity.name);
    identityJSONObject.put("firstName", identity.firstName);
    identityJSONObject.put("middleName", identity.middleName);
    identityJSONObject.put("dateOfBirth", simpleDateFormat.format(identity.dateOfBirth.getTime()));
    identityJSONObject.put("placeOfBirth", identity.placeOfBirth);
    identityJSONObject.put("gender", identity.gender.toString());

    JSONObject cardJSONObject = new JSONObject();
    eidJSONObject.put("card", cardJSONObject);
    cardJSONObject.put("cardNumber", identity.cardNumber);
    cardJSONObject.put("chipNumber", identity.chipNumber);
    cardJSONObject.put("cardDeliveryMunicipality", identity.cardDeliveryMunicipality);
    cardJSONObject.put("cardValidityDateBegin",
            simpleDateFormat.format(identity.cardValidityDateBegin.getTime()));
    cardJSONObject.put("cardValidityDateEnd", simpleDateFormat.format(identity.cardValidityDateEnd.getTime()));

    Address address = eIdData.address;/*  www  .  java 2 s .com*/
    if (null != address) {
        JSONObject addressJSONObject = new JSONObject();
        eidJSONObject.put("address", addressJSONObject);
        addressJSONObject.put("streetAndNumber", address.streetAndNumber);
        addressJSONObject.put("municipality", address.municipality);
        addressJSONObject.put("zip", address.zip);
    }

    EIdCertsData certsData = eIdData.certs;
    if (null != certsData) {
        JSONObject certsJSONObject = new JSONObject();
        eidJSONObject.put("certs", certsJSONObject);

        X509Certificate authnCertificate = certsData.authn;
        JSONObject authnCertJSONObject = createCertJSONObject(authnCertificate, simpleDateFormat);
        certsJSONObject.put("authn", authnCertJSONObject);

        X509Certificate signCertificate = certsData.sign;
        JSONObject signCertJSONObject = createCertJSONObject(signCertificate, simpleDateFormat);
        certsJSONObject.put("sign", signCertJSONObject);

        X509Certificate citizenCACertificate = certsData.ca;
        JSONObject citizenCACertJSONObject = createCertJSONObject(citizenCACertificate, simpleDateFormat);
        certsJSONObject.put("citizenCA", citizenCACertJSONObject);

        X509Certificate rootCACertificate = certsData.root;
        JSONObject rootCACertJSONObject = createCertJSONObject(rootCACertificate, simpleDateFormat);
        certsJSONObject.put("rootCA", rootCACertJSONObject);
    }

    eidJSONObject.writeJSONString(writer);
}

From source file:cv_vacature_bank.Jsonhandler.java

public void VacatureJson(Vacature vc) {
    if (vc == null) {
        return;/* w w  w.  ja  v a  2  s .c  om*/
    }
    JSONObject vcj = new JSONObject();
    vcj.put("url", vc.getUrl());
    vcj.put("beroep", vc.getBeroep());
    vcj.put("omschrijving", vc.getOmschrijving());
    vcj.put("regio", vc.getRegio());
    vcj.put("sector", vc.getSector());
    vcj.put("niveau", vc.getNiveau());
    vcj.put("dienstverband", vc.getDienstverband());
    vcj.put("bedrijfsprofiel", vc.getBedrijfsprofiel());
    vcj.put("aanbod", vc.getAanbod());
    vcj.put("eigenschappen", vc.getEigenschappen());
    vcj.put("eisen", vc.getEisen());
    vcj.put("kennis", vc.getKennis());

    objs.add(vcj);

    if (objs.size() == 20) {
        createFile("Vacature");
        objs.clear();
    }

}

From source file:cc.pinel.mangue.storage.StateStorage.java

public void setChapter(String mangaId, String chapterNumber) throws IOException {
    JSONObject json = null;//  www  . j a v  a2 s. c  o  m

    try {
        json = readJSON();
    } catch (Exception e) {
        // ignored
    }
    if (json == null)
        json = new JSONObject();

    JSONArray jsonMangas = (JSONArray) json.get("mangas");
    if (jsonMangas == null) {
        jsonMangas = new JSONArray();
        json.put("mangas", jsonMangas);
    }

    JSONObject jsonManga = findManga(jsonMangas, mangaId);
    if (jsonManga == null) {
        jsonManga = new JSONObject();
        jsonManga.put("id", mangaId);
        jsonMangas.add(jsonManga);
    }
    jsonManga.put("chapterNumber", chapterNumber);

    writeJSON(json);
}

From source file:control.ParametrizacionServlets.EliminarTecnicos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from   w  w  w. j  a va 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 {

    try {

        int codigo = Integer.parseInt(request.getParameter("codigo"));
        JSONObject respError = new JSONObject();

        Tecnicos manager = new Tecnicos();
        respError = manager.Eliminar(codigo);

        response.setContentType("application/json");

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

    } catch (Exception e) {
    }

}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Course.java

@SuppressWarnings("unchecked")
@Override/*w  w  w  .j ava  2s  . c  om*/
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "course");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", courseOverGround);
    }
    return o.toJSONString();
}

From source file:com.github.sourjson.translat.def.DateTranslater.java

@SuppressWarnings("unchecked")
@Override//w ww  .j av  a 2 s.com
public @CheckForNull JSONObject serialize(Date obj, Type typeOnServer, AnnotatedElement el,
        @CheckForNull Object enclosing, SourJson json, double version) {
    JSONObject ret = new JSONObject();
    ret.put("GMT", formater.format(obj));
    return ret;
}

From source file:com.imagelake.android.search.Servlet_Components.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from  w  w w .  ja v a2s.c  om*/

        jja = new JSONArray();

        JSONArray kja = kwdi.getJSONAllKeyWords();
        jja.add(kja);

        List<Categories> categories = cdi.listAllCategories();
        JSONArray cja = new JSONArray();
        for (Categories c : categories) {
            JSONObject jo = new JSONObject();
            jo.put("id", c.getCategory_id());
            jo.put("cat", c.getCategory());
            cja.add(jo);
        }
        jja.add(cja);

        JSONArray sja = new JSONArray();
        List<User> li = new UserDAOImp().listAllSellers();
        if (!li.isEmpty()) {

            for (User u : li) {
                JSONObject jo = new JSONObject();
                jo.put("id", u.getUser_id());
                jo.put("nm", u.getUser_name());
                sja.add(jo);
            }
        }
        jja.add(sja);

        JSONArray ja = new JSONArray();
        List<Credits> clist = new CreditsDAOImp().getCreditList();
        for (Credits c : clist) {
            JSONObject jo = new JSONObject();
            jo.put("width", c.getWidth());
            jo.put("height", c.getHeight());
            ja.add(jo);
        }
        jja.add(ja);
        System.out.println(jja.toJSONString());
        out.write("json=" + jja.toJSONString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:control.ProcesoVertimientosServlets.EliminarProcesoVertimientos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*  ww  w  .  j a va 2 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 resp = new JSONObject();
    try {
        int codigo = Integer.parseInt(request.getParameter("codigo"));

        ProcesoVertimientos manager = new ProcesoVertimientos();

        resp = manager.eliminarProcesoVertimiento(codigo);

        response.setContentType("application/json");
        response.getWriter().write(resp.toString());

    } catch (Exception ex) {
        resp.put("error", 0);
        response.getWriter().write(resp.toString());
    }

}

From source file:LicenseKeyAPI.java

/**
 * Registers the application with the server
 *
 * @param   licenseKey  The license key to register with the server.
 * @param   appID       The application ID to register with the server.
 * @param   userEmail   The users email to register the app with the server.
 * @return              The status code returned from the server.
 **//*from   w  w  w  .  j  av  a 2 s.co  m*/
public int registerApp(String licenseKey, String appID, String userEmail) {
    String URLpostFixEndpoint = "api/client/register_application";

    // Creates HTTP POST request
    HttpPost httppost = new HttpPost(baseServerURLAddress + URLpostFixEndpoint);
    httppost.addHeader("Content-Type", "application/json");
    httppost.setHeader("Content-Type", "application/json; charset= utf-8");
    httppost.setHeader("Accept", "application/json");

    JSONObject json = new JSONObject();
    json.put("email", userEmail);
    json.put("licensekey", licenseKey);
    json.put("appID", appID);

    StringEntity entity = new StringEntity(json.toString(), "utf-8");

    // Adds the POST params to the request
    httppost.setEntity(entity);

    return sendPOST(httppost);
}

From source file:com.saludtec.web.ClaveCorreccionWeb.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("/Adminio/claveCorreccion/", "");
        switch (servicio) {
        case "getpass":
            traerClaveCorreccion(request).writeJSONString(out);
            break;

        case "pass":
            editarClaveCorreccion(request).writeJSONString(out);
            break;

        default:/*  w  w w .  j  a  v a2  s. c  om*/
            obj = new JSONObject();
            obj.put("error", "404 - El servicio " + servicio + " no existe");
            obj.writeJSONString(out);
            break;

        }

    } catch (NonexistentEntityException ex) {
        Logger.getLogger(ClaveCorreccionWeb.class.getName()).log(Level.SEVERE, null, ex);
    }
}