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:fr.nantes.web.quizz.servlets.Nbdirectors.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int countdirectors = Requetesdatastore.getcountdirectors();
    JSONArray result = new JSONArray();
    JSONObject map = new JSONObject();
    map.put("count", countdirectors);
    result.add(map);//  w  ww. j  a  va 2  s  . co m

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

        out.println(result);
    }
}

From source file:bhl.pages.handler.PagesCropRectHandler.java

/**
 * Make a default crop rect when the page doesn't specify one
 * @return a JSONArray/*from   w  w w  .  j a v  a  2s  .  c  om*/
 */
private JSONArray getDefaultCropRect() {
    JSONArray outer = new JSONArray();
    JSONArray tl = new JSONArray();
    tl.add(0.0);
    tl.add(0.0);
    outer.add(tl);
    JSONArray tr = new JSONArray();
    tr.add(100.0);
    tr.add(0.0);
    outer.add(tr);
    JSONArray br = new JSONArray();
    br.add(100.0);
    br.add(100.0);
    outer.add(br);
    JSONArray bl = new JSONArray();
    bl.add(0.0);
    bl.add(100.0);
    outer.add(bl);
    return outer;
}

From source file:modelo.ParametrizacionManagers.TiposContactos.java

/**
* 
* Llama al delegate para Eliminar una tipo de contacto
* @param codigo     //  ww w  . j  ava2  s .  c o  m
* @throws Exception 
*/

public JSONArray eliminar(int codigo) throws Exception {

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

    Integer respError;

    EliminarTiposContactos delete = new EliminarTiposContactos(codigo);

    delete.ejecutar();

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;
}

From source file:modelo.ParametrizacionManagers.MotivosVisitas.java

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

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

    Integer respError;

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

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:fr.nantes.web.quizz.servlets.Adddirectors.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int nbdirectors = Integer.parseInt(request.getParameter("nbdirectors"));

    JSONArray result = new JSONArray();
    JSONObject map = new JSONObject();
    if (nbdirectors > Requetesdatastore.getcountdirectors()) {
        if (Requetesdatastore.adddirectors(nbdirectors)) {
            map.put("count", nbdirectors);
            result.add(map);/* w  w w . j  av a2  s .  c  o  m*/
        } else {
            map.put("count", 0);
            result.add(map);
        }
    } else {
        map.put("count", -100);
        result.add(map);
    }
    response.setContentType("application/json;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

        out.println(result);
    }
}

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

public Collection getMangas() {
    Collection mangas = new ArrayList();

    JSONArray jsonMangas = null;/*from  w  w  w  . jav a2s .  c o m*/
    try {
        jsonMangas = (JSONArray) readJSON().get("mangas");
    } catch (Exception e) {
        // ignored
    }
    if (jsonMangas == null)
        jsonMangas = new JSONArray();

    for (int i = 0; i < jsonMangas.size(); i++) {
        JSONObject jsonManga = (JSONObject) jsonMangas.get(i);
        mangas.add(new Manga(jsonManga.get("id").toString(), jsonManga.get("name").toString(),
                jsonManga.get("path").toString()));
    }

    return mangas;
}

From source file:geo.controller.LoadMRTServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w  w.  ja  va  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");
    PrintWriter out = response.getWriter();
    try {
        ArrayList<MRTStation> mrtList = MRTStationDAO.getMRTList();

        JSONArray jsonArray = new JSONArray();
        int index = 0;

        for (int i = 0; i < mrtList.size(); i++) {
            if (mrtList.get(i).lat == 0 && mrtList.get(i).lng == 0) {
                continue;
            }
            jsonArray.add(index++, mrtList.get(i).getJSONObject());
        }

        out.println(jsonArray.toJSONString());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.close();
    }
}

From source file:control.ProcesoVertimientosServlets.ContarParametros.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*ww w .j  a va 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 doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {

        String codigoProceso = request.getParameter("codigoProceso");
        JSONArray jsonArray = new JSONArray();

        PDFManager manager = new PDFManager();
        jsonArray = manager.contarParam(codigoProceso);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        for (Object jsonObject : jsonArray) {

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

        }

    } catch (Exception ex) {
        //Logger.getLogger(SeleccionarLodos.class.getName()).log(Level.SEVERE, null, ex);
    }

}

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 {/*  w w w . j ava2  s  .  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:Manager.addEmployee.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w  ww .  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 {
    //json to pass back to our ajax request
    JSONArray jsonArray = new JSONArray();
    PrintWriter printout = response.getWriter();
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw");

        Statement st = con.createStatement();
        String SSN = request.getParameter("SSN");
        String Password = request.getParameter("Password");
        String FirstName = request.getParameter("FirstName");
        String LastName = request.getParameter("LastName");
        String Street = request.getParameter("Street");
        String City = request.getParameter("City");
        String State = request.getParameter("State");
        String ZipCode = request.getParameter("ZipCode");
        String Email = request.getParameter("Email");
        String Telephone = request.getParameter("Telephone");
        String Role = request.getParameter("Role");
        String Rate = request.getParameter("Rate");
        Date currTime = new Date();
        Timestamp creationDate = new Timestamp(currTime.getTime());

        String query = "SELECT * FROM PERSON WHERE SSN = '" + SSN + "'";
        System.out.println(query);
        ResultSet rs = st.executeQuery(query);

        if (!rs.next()) {
            query = "INSERT INTO [MatchesFromAbove].[dbo].[Person] " + "VALUES('" + SSN + "', '" + Password
                    + "', '" + FirstName + "', '" + LastName + "','" + Street + "','" + City + "','" + State
                    + "'," + ZipCode + ",'" + Email + "','" + Telephone + "');\n"
                    + "INSERT INTO [MatchesFromAbove].[dbo].[Employee] " + "VALUES('" + SSN
                    + "', 'User-User', '" + creationDate + "'," + Rate + ", 1); ";
            System.out.println(query);
            st.executeUpdate(query);

        } else {

            query = "INSERT INTO [MatchesFromAbove].[dbo].[Employee] " + "VALUES('" + SSN + "', 'User-User', '"
                    + creationDate + "'," + Rate + ", 1); ";
            System.out.println(query);
            st.executeUpdate(query);
        }

        //set the content type of our response
        response.setContentType("application/json");
        //printout prints it to our ajax call and it shows up there as data. you can use this data in the success function.
        printout.print("success");
        printout.flush();
    } catch (Exception e) {
        printout.print("failure");
        System.out.println("NO IDEA - - - " + e);
    }
}