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:client.InterfaceJeu.java

/**
 * Creates new form InterfaceJeu/*from ww w  . j av a2  s .  c  om*/
 * @param cl
 */
public InterfaceJeu(Client cl) {
    initComponents();
    this.c = cl;
    this.infosJoueurs = new JSONArray();
    this.cartes = new JSONArray();
    this.cartesJouables = new JSONArray();
    parser = new JSONParser();
    this.imgCartes = new ArrayList();
    this.imgCartesPosees = new ArrayList();
    this.cartesSelectionnees = new ArrayList();
    this.cartesJouablesString = new ArrayList();
    this.jButton1.setVisible(false);
    this.jButton2.setVisible(false);
    tourName = "";
    interSession = false;
    DefaultCaret caret = (DefaultCaret) this.txtAreaChatLect.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
}

From source file:control.ParametrizacionServlets.EliminarTiposInformeVertimientos.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 {

        //Obtenemos los paramtros enviados
        int codigo = Integer.parseInt(request.getParameter("codigo"));

        JSONArray respError = new JSONArray(); // uno significa que no hay error

        //Obtenemos La informacion del manager
        TiposInformeVertimientos manager = new TiposInformeVertimientos();
        //Almacenamos el error que pueda resultar
        respError = manager.Eliminar(codigo);

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

        for (Object jsonObject : respError) {

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

        }

    } catch (Exception e) {

    }

}

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]);/*from  w  w  w.ja v a2  s .c  o m*/
    }
    return ja;
}

From source file:com.wso2.mobile.mdm.api.TrackCallSMS.java

/**
 * Returns a JSONArray of call detail objects Ex: [{number:"0112345666", type:"INCOMING", date:"dd/MM/yyyy hh:mm:ss.SSS", duration:"90"}]
 *//*from   www  . j a  v a  2 s .  c  om*/
public JSONArray getCallDetails() {
    JSONArray jsonArray = null;
    try {
        Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, null, null, null, null);
        int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
        int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
        int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
        jsonArray = new JSONArray();

        while (managedCursor.moveToNext()) {
            JSONObject jsonObj = new JSONObject();
            String phNumber = managedCursor.getString(number);
            String callType = managedCursor.getString(type);
            String callDate = managedCursor.getString(date);
            Date callDayTime = new Date(Long.valueOf(callDate));
            String callDuration = managedCursor.getString(duration);
            String dir = null;
            int dircode = Integer.parseInt(callType);
            switch (dircode) {
            case CallLog.Calls.OUTGOING_TYPE:
                dir = "OUTGOING";
                break;

            case CallLog.Calls.INCOMING_TYPE:
                dir = "INCOMING";
                break;

            case CallLog.Calls.MISSED_TYPE:
                dir = "MISSED";
                break;
            }
            jsonObj.put("number", phNumber);
            jsonObj.put("type", dir);
            jsonObj.put("date", callDayTime);
            jsonObj.put("duration", callDuration);
            jsonArray.add(jsonObj);
        }

        managedCursor.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return jsonArray;
}

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

        case "traerUltimo":
            traerUltimoExamenFisico(request).writeJSONString(out);
            break;

        case "traerFecha":
            traerExamenFisicoFecha(request).writeJSONString(out);
            break;

        default:/*from   w w w .ja  va 2  s  . 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:modelo.ParametrizacionManagers.Laboratorios.java

/**
* 
* Llama al delegate para Eliminar un Laboratorio
* 
* @param codigo     //from ww w. j  a  va 2 s  .c o  m
* @throws Exception 
*/
public JSONArray Eliminar(int codigo) throws Exception {

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

    Integer respError;

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

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:modelo.ParametrizacionManagers.DocumentacionRequerida.java

/**
* 
* Llama al delegate para Eliminar una unidad de medida.
* 
* @param codigo     /* ww w .ja va 2  s  .com*/
* @throws Exception 
*/
public JSONArray eliminar(int codigo) throws Exception {

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

    Integer respError;

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

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

From source file:net.duckling.ddl.web.AbstractRecommendContrller.java

@SuppressWarnings("unchecked")
protected void prepareRecommend(HttpServletResponse response) {
    Team team = teamService.getTeamByID(VWBContext.getCurrentTid());
    List<SimpleUser> candidates = teamMemberService.getTeamMembersOrderByName(team.getId());
    Collections.sort(candidates, comparator);
    JSONArray array = new JSONArray();
    for (SimpleUser current : candidates) {
        JSONObject temp = new JSONObject();
        temp.put("id", current.getUid());
        if (StringUtils.isNotEmpty(current.getName())) {
            temp.put("name", current.getName());
        } else {/*w w  w.j av a 2  s.c o  m*/
            temp.put("name", current.getUid());
        }
        temp.put("userExtId", current.getId());
        array.add(temp);
    }
    JsonUtil.writeJSONObject(response, array);
}

From source file:com.assignment4.products.Pro_details.java

/**
 * Retrieves representation of an instance of com.oracle.products.ProductResource
 * @return an instance of java.lang.String
 *///  w w  w  .ja va  2  s . com
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getAllProducts() throws SQLException {
    if (conn == null) {
        return "not connected";
    } else {
        String q = "Select * from products";
        PreparedStatement ps = conn.prepareStatement(q);
        ResultSet rs = ps.executeQuery();
        String r = "";
        JSONArray proArr = new JSONArray();
        while (rs.next()) {
            Map pm = new LinkedHashMap();
            pm.put("productID", rs.getInt("product_id"));
            pm.put("name", rs.getString("name"));
            pm.put("description", rs.getString("description"));
            pm.put("quantity", rs.getInt("quantity"));
            proArr.add(pm);
        }
        r = proArr.toString();
        return r.replace("},", "},\n");
    }

}

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

public static void ApacheOpenNLP(String doc, String args[]) {
    try {// w  w  w .  java2 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();
        String metaValue = metadata.toString();
        System.out.println("Desc:: " + metadata.get("description"));

        String[] example = new String[1];
        example[0] = text;
        String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu");
        Map<String, Set<String>> list = tikaOpenNLP(text);
        System.out.println(combineSets(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 : OpenNLP" + "|File Name"
                + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString());
    }
}