Example usage for org.json.simple JSONArray JSONArray

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

Introduction

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

Prototype

JSONArray

Source Link

Usage

From source file:control.ParametrizacionServlets.EliminarConsultores.java

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

    try {

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

        Consultores manager = new Consultores();

        respError = manager.Eliminar(codigo);

        for (Object jsonObject : respError) {

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

        }

    } catch (Exception e) {
    }

}

From source file:modelo.ParametrizacionManagers.Consultores.java

/**
* 
* Llama al delegate para Eliminar un Consultorio
* 
* @param codigo     //from w  w w . j  av  a  2 s .  c  om
* @throws Exception 
*/
public JSONArray Eliminar(int codigo) throws Exception {

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

    Integer respError;

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

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:br.bireme.mlts.utils.Document2JSON.java

public static JSONObject getJSON(final Map<String, List<Fieldable>> map) {
    if (map == null) {
        throw new NullPointerException("map");
    }/* w w  w .ja  v a2s  . com*/

    final JSONObject jobj = new JSONObject();

    for (Map.Entry<String, List<Fieldable>> entry : map.entrySet()) {
        final String key = entry.getKey();
        final List<Fieldable> value = entry.getValue();
        final boolean multivalue = value.size() > 1;

        if (multivalue) {
            final JSONArray array = new JSONArray();
            jobj.put(key, array);
            for (Fieldable fld : value) {
                array.add(getObject(fld));
            }
        } else {
            jobj.put(key, getObject(value.get(0)));
        }
    }
    return jobj;
}

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

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w w .j av  a2 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 {

    //on rcupre la valeur recupr du moteur de recherche.
    String Libelle = request.getParameter("libelle_recherche");

    HttpSession session = request.getSession();

    JSONObject global = new JSONObject();
    JSONArray arrayoffre = new JSONArray();

    ArrayList<Offre> listOffresSearch = new ArrayList();
    for (Offre offre : offreDAO.Lister()) {

        if (recherche(offre.getLibelle(), Libelle) > 0) {

            listOffresSearch.add(offre);

        }

    }

    for (Offre offre : listOffresSearch) {

        JSONObject object = new JSONObject();
        object.put("Identifiant", offre.getIdentifiant());
        object.put("Intitule", offre.getLibelle());
        object.put("Reference", offre.getReference());
        object.put("DateDebutContrat", offre.getDateDebutContrat().toString());
        object.put("NombresPoste", offre.getNbPoste());
        object.put("VilleEntreprise", offre.getClient().getVilleEntreprise());
        arrayoffre.add(object);

    }
    global.put("offres", arrayoffre);
    global.put("container_search", Libelle);
    session.setAttribute("offres_lib", global);

    RequestDispatcher rq = request.getRequestDispatcher("offres.html");
    rq.forward(request, response);

}

From source file:Activities.java

private String addData(String endpoint) {
    String data = null;//from   w ww .j av a2 s . com
    try {
        // Construct request payload
        JSONObject attrObj = new JSONObject();
        attrObj.put("name", "URL");
        attrObj.put("value", "http://www.nvidia.com/game-giveaway");

        JSONArray attrArray = new JSONArray();
        attrArray.add(attrObj);

        TimeZone tz = TimeZone.getTimeZone("UTC");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
        df.setTimeZone(tz);
        String dateAsISO = df.format(new Date());

        // Required attributes
        JSONObject obj = new JSONObject();
        obj.put("leadId", "1001");
        obj.put("activityDate", dateAsISO);
        obj.put("activityTypeId", "1001");
        obj.put("primaryAttributeValue", "Game Giveaway");
        obj.put("attributes", attrArray);
        System.out.println(obj);

        // Make request
        URL url = new URL(endpoint);
        HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
        urlConn.setRequestMethod("POST");
        urlConn.setAllowUserInteraction(false);
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-type", "application/json");
        urlConn.setRequestProperty("accept", "application/json");
        urlConn.connect();
        OutputStream os = urlConn.getOutputStream();
        os.write(obj.toJSONString().getBytes());
        os.close();

        // Inspect response
        int responseCode = urlConn.getResponseCode();
        if (responseCode == 200) {
            System.out.println("Status: 200");
            InputStream inStream = urlConn.getInputStream();
            data = convertStreamToString(inStream);
            System.out.println(data);
        } else {
            System.out.println(responseCode);
            data = "Status:" + responseCode;
        }
    } catch (MalformedURLException e) {
        System.out.println("URL not valid.");
    } catch (IOException e) {
        System.out.println("IOException: " + e.getMessage());
        e.printStackTrace();
    }

    return data;
}

From source file:com.owly.srv.BasicDataMetricInJson.java

/**
 * Constructor used to initialize the object and assign the label. 
 * @param label label to show in the graph of the statistic
 *  /*from w  w w  .  j a v  a 2  s  .c  o  m*/
 */
public BasicDataMetricInJson(String label) {
    super();
    logger.debug("Calling constructor with label = " + label);
    this.label = label;
    JSONArray jsonArray = new JSONArray();
    this.jsonDataArray = jsonArray;
    logger.debug("Constructor Ended");
}

From source file:modelo.UsuariosManagers.Usuarios.java

/**
 * /*from www .  j a va 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:controller.RetrieveSchema.java

@SuppressWarnings("unchecked")
public String retrieveSchema(String _projectId) throws IOException, DatabaseException, MissingPropertiesFile,
        SQLException, ConnectionClosedException, DatabaseValueNotFoundException {

    JSONObject obj = new JSONObject();
    dao = new GetSchemaDao();
    Schema schema = dao.getSchema(Integer.parseInt(_projectId));

    JSONArray tables = new JSONArray();
    JSONArray columns = new JSONArray();
    for (Table table : schema.getTables()) {

        tables.add(table.getName());/*  ww  w . j  a  v  a 2  s. co m*/
    }

    for (Column column : schema.getColumns()) {
        columns.add(column.getName());
    }

    obj.put("tables", tables);
    obj.put("columns", columns);

    return json.nestedJson(State.PASSED, obj);

}

From source file:org.kitodo.data.index.elasticsearch.type.UserType.java

@SuppressWarnings("unchecked")
@Override/*from  ww w .  java 2 s .c o  m*/
public HttpEntity createDocument(User user) {

    LinkedHashMap<String, String> orderedUserMap = new LinkedHashMap<>();
    orderedUserMap.put("name", user.getName());
    orderedUserMap.put("surname", user.getSurname());
    orderedUserMap.put("login", user.getLogin());
    orderedUserMap.put("ldapLogin", user.getLdapLogin());
    orderedUserMap.put("active", String.valueOf(user.isActive()));
    orderedUserMap.put("location", user.getLocation());
    orderedUserMap.put("metadataLanguage", user.getMetadataLanguage());
    String ldapGroup = user.getLdapGroup() != null ? user.getLdapGroup().getId().toString() : "null";
    orderedUserMap.put("ldapGroup", ldapGroup);

    JSONObject userObject = new JSONObject(orderedUserMap);

    JSONArray userGroups = new JSONArray();
    List<UserGroup> userUserGroups = user.getUserGroups();
    for (UserGroup userGroup : userUserGroups) {
        JSONObject userGroupObject = new JSONObject();
        userGroupObject.put("id", userGroup.getId().toString());
        userGroups.add(userGroupObject);
    }
    userObject.put("userGroups", userGroups);

    JSONArray properties = new JSONArray();
    List<UserProperty> userProperties = user.getProperties();
    for (UserProperty property : userProperties) {
        JSONObject propertyObject = new JSONObject();
        propertyObject.put("title", property.getTitle());
        propertyObject.put("value", property.getValue());
        properties.add(propertyObject);
    }
    userObject.put("properties", properties);

    return new NStringEntity(userObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:com.imagelake.android.privilages.Servlet_privilages.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {//www. ja  v a  2  s . co m

        String user_type = request.getParameter("user_type");

        if (user_type != null) {

            if (Integer.parseInt(user_type) != 4) {
                privilageArray = new JSONArray();

                li = pdi.listAll(Integer.parseInt(user_type));

                if (!li.isEmpty()) {

                    for (Privilages privilages : li) {
                        if (privilages.getState() == 1) {

                            inf = infs.getInterfaceName(privilages.getInterface_interface_id());

                            JSONObject jo = new JSONObject();
                            jo.put("interface", inf.getDisplay_name());
                            jo.put("imgId", inf.getImg_id());
                            System.out.println(inf.getImg_id());
                            privilageArray.add(jo);

                        }
                    }

                    out.write("json=" + privilageArray.toJSONString());

                } else {
                    out.write("msg=No privilages.");
                }
            } else {
                out.write("msg=Incorrect user type.");
            }

        } else {
            out.write("msg=User type error.");
        }

    } catch (Exception e) {
        e.printStackTrace();
        out.write("msg=Internal server error,Please try again later.");
    }

}