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:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarUsuariosEnConvocatoriaId(HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnConvocatoria(Integer.parseInt(request.getParameter("3")), //id evento
            Integer.parseInt(request.getParameter("2")), //tamao tabla
            Integer.parseInt(request.getParameter("1"))//pagina
    );/*from   w w  w  .  ja v a2  s  .  co m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);
    }
    out.print(list1);
}

From source file:com.avatarproject.core.storage.UserCache.java

/**
 * Adds a player into the custom UserCache.
 * @param player Player to add to the cache.
 *//*from  www  . j  a  v a  2s  .co  m*/
@SuppressWarnings("unchecked")
public static void addUser(Player player) {
    String name = player.getName();
    UUID uuid = player.getUniqueId();
    JSONArray array = getUserCache();
    try {
        for (int n = 0; n < array.size(); n++) { //Loop through all the objects in the array.
            JSONObject object = (JSONObject) array.get(n);
            if (object.get("id").equals(uuid.toString())) { //Check if the player's UUID exists in the cache.
                if (String.valueOf(object.get("name")).equalsIgnoreCase(name)) {
                    return;
                } else {
                    object.put("name", name); //Update the user.
                    FileWriter fileOut = new FileWriter(usercache);
                    fileOut.write(array.toJSONString()); //Write the JSON array to the file.
                    fileOut.close();
                    return;
                }
            }
        }
        JSONObject newEntry = new JSONObject();
        newEntry.put("id", uuid.toString());
        newEntry.put("name", name);
        array.add(newEntry); //Add a new player into the cache.
        FileWriter fileOut = new FileWriter(usercache);
        fileOut.write(array.toJSONString()); //Write the JSON array to the file.
        fileOut.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cloudera.hoop.fs.FSSetReplication.java

/**
 * Executes the filesystem operation./*www  .j a  v  a 2 s  .  c om*/
 *
 * @param fs filesystem instance to use.
 * @return <code>true</code> if the replication value was set,
 * <code>false</code> otherwise.
 * @throws IOException thrown if an IO error occured.
 */
@Override
@SuppressWarnings("unchecked")
public JSONObject execute(FileSystem fs) throws IOException {
    boolean ret = fs.setReplication(path, replication);
    JSONObject json = new JSONObject();
    json.put("setReplication", ret);
    return json;
}

From source file:com.megacasting_ppe.web.ServletLoadOffreView.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  w w .  j av a  2  s .c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json");
    response.setHeader("Cache-Control", "no-cache");
    HttpSession session = request.getSession();

    JSONObject global = (JSONObject) session.getAttribute("offres_lib");

    Candidat candidat = (Candidat) session.getAttribute("CandidatObject");
    String connecterOk = (String) session.getAttribute("Connecter");

    if (candidat != null && connecterOk != null) {

        JSONObject infoAuth = new JSONObject();

        infoAuth.put("Nom", candidat.getNom());
        infoAuth.put("Prenom", candidat.getPrenom());
        infoAuth.put("connecter", connecterOk);

        global.put("infoauth", infoAuth);

    } else {

        JSONObject infoAuth = new JSONObject();
        infoAuth.put("connecter", "false");

        global.put("infoauth", infoAuth);
    }

    try (PrintWriter out = response.getWriter()) {
        out.println(global.toString());
    }

}

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

        case "listar":
            out.println(listarEvolucion(request));
            break;

        default:/*from w  w  w.  j a  v a2s  .  c o  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:org.jboss.aerogear.unifiedpush.test.util.AuthenticationUtils.java

public static boolean changePassword(String loginName, String oldPassword, String newPassword, String root) {
    Validate.notNull(root);//  w  w w .j  a v  a  2  s .  c  om

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("loginName", loginName);
    jsonObject.put("password", oldPassword);
    jsonObject.put("newPassword", newPassword);

    // FIXME should not this be using already existing session?
    Response response = Session.newSession(root).given().contentType(ContentTypes.json())
            .header(Headers.acceptJson()).body(jsonObject.toJSONString()).put("/rest/auth/update");

    if (response.statusCode() == HttpStatus.SC_OK) {
        return true;
    } else if (response.statusCode() == HttpStatus.SC_UNAUTHORIZED) {
        throw new InvalidPasswordException(response);
    } else {
        throw new UnexpectedResponseException(response);
    }
}

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

@SuppressWarnings("unchecked")
@Override//from   w  w  w  .  j  a  v  a2 s.c om
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_TEMPERATURE);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", temperature);
    }
    return o.toJSONString();
}

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

@SuppressWarnings("unchecked")
@Override//w  w  w  .  j  a  v  a  2s . c  om
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", ISensorProxy.SENSOR_NAME_AIR_PRESSURE);
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", airPressure);
    }
    return o.toJSONString();
}

From source file:ch.simas.jtoggl.Workspace.java

public JSONObject toJSONObject() {
    JSONObject object = new JSONObject();
    if (id != null) {
        object.put("id", id);
    }/*ww  w  . ja v  a2s . c  om*/
    if (name != null) {
        object.put("name", name);
    }
    if (premium != null) {
        object.put("premium", premium);
    }
    return object;
}

From source file:edu.usc.polar.NLTKRest.java

public static void ApacheNLTKRest(String doc, String args[]) {
    try {//  w  w w  .j a v a2 s  .  c  o  m
        String text;
        AutoDetectParser parser = new AutoDetectParser();
        BodyContentHandler handler = new BodyContentHandler();
        Metadata metadata = new Metadata();

        InputStream stream = new FileInputStream(doc);
        // System.out.println(stream.toString());
        parser.parse(stream, handler, metadata);
        // return handler.toString();
        text = handler.toString();
        //System.out.println(text);
        String metaValue = metadata.toString();
        System.out.println("Desc:: " + metadata.toString());

        String[] example = new String[1];
        example[0] = text;
        String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu");
        //System.out.println(text);
        Map<String, Set<String>> list = tikaNLTKRest(text);
        System.out.println(list);
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("DOI", name);
        jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " "));
        JSONArray tempArray = new JSONArray();
        JSONObject tempObj = new JSONObject();
        for (Map.Entry<String, Set<String>> entry : list.entrySet()) {
            System.out.println("\"" + entry.getKey() + "/" + ":\"" + entry.getValue() + "\"");
            tempObj.put(entry.getKey(), entry.getValue());
            //          String jsonOut="{ DOI:"+name+"  ,"
            //                + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\""
            //                + "\"metadata\":\""+metaValue+"\""
            //                + "}";
            // System.out.println(jsonOut);
            //     tempObj.put(item.first(),text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," "));
        }
        tempArray.add(tempObj);
        jsonObj.put("NER", tempArray);
        jsonArray.add(jsonObj);

        // System.out.println("---");

    } catch (Exception e) {
        System.out.println("ERROR : NLTKRest" + "|File Name"
                + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString());
    }
}