Example usage for org.json.simple JSONArray size

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

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:guestbook.Entity.java

public String getValue(String p) {
    if (statements == null)
        return null;
    Set s = statements.keySet();//from w  w w  . j  av a2  s  .c  om
    if (s.contains(p)) {
        String str = "";
        JSONArray statement = (JSONArray) statements.get(p);
        for (int i = 0; i < statement.size(); i++) {
            JSONObject x = (JSONObject) statement.get(i);
            JSONObject mainsnak = (JSONObject) x.get("mainsnak");
            Set g = mainsnak.keySet();
            if (!g.contains("datatype")) {
                System.out.println(getId() + " :No datatype");
                return null;
            }
            String snaktype = (String) mainsnak.get("snaktype");
            if (snaktype.equals("somevalue"))
                return "Unknown value" + "001";
            String type = (String) mainsnak.get("datatype");
            JSONObject datavalue = (JSONObject) mainsnak.get("datavalue");
            switch (type) {
            case "wikibase-item":
                JSONObject value = (JSONObject) datavalue.get("value");
                str = str + (Long) value.get("numeric-id") + "xxx";
                break;
            case "string":
                str = str + (String) datavalue.get("value") + "001";
                break;
            case "quantity":
                JSONObject values = (JSONObject) datavalue.get("value");
                String ss = (String) values.get("amount");
                str = str + ss.substring(1) + "001";
                break;
            case "commonsMedia":
                str = str + (String) datavalue.get("value") + "001";
                break;
            case "globe-coordinate":
                final String d = "\u00b0";
                JSONObject value2 = (JSONObject) datavalue.get("value");
                String lat = value2.get("latitude").toString();
                String lon = value2.get("longitude").toString();
                str = str + lat + d + "N " + lon + d + "E " + "001";
                break;
            case "time":
                JSONObject value3 = (JSONObject) datavalue.get("value");
                //GregorianCalendar gc = (GregorianCalendar) value3.get("time");
                String gc = (String) value3.get("time");
                //String gcs = gc.c
                str = str + gc + "001";
                break;
            case "url":
                str = str + (String) datavalue.get("value") + "001";
                break;
            default:
                break;
            }
        }
        if (str.length() > 0) {
            return str.trim();
        }
    }
    return null;
}

From source file:logica.ABB.java

public void llenar(JSONArray array) {
    ABB ar = new ABB();
    for (int i = 0; i < array.size(); i++) {
        ar.insertar(array.get(i));/* w w w.  ja v a  2s.com*/
    }
}

From source file:control.ProcesoVertimientosServlets.InsertarVerificacionInfoCaracterizacion.java

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

        //Obtenemos la cadena con la informacion y la convertimos en un
        //JSONArray
        String respuestas = request.getParameter("respuestas");
        Integer codigoProceso = Integer.parseInt(request.getParameter("codigoProceso"));
        Object obj = JSONValue.parse(respuestas);
        JSONArray jsonArray = new JSONArray();
        jsonArray = (JSONArray) obj;

        //Recorremos el JSONArray y obtenemos la informacion.
        for (int i = 0; i < jsonArray.size(); i++) {

            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            String checkeado = (String) jsonObject.get("checkeado");
            Integer codigo = Integer.parseInt((String) jsonObject.get("codigo"));

            //Creamos el manager y guardamos la informacion.
            VerificacionInfoCaracterizacion manager = new VerificacionInfoCaracterizacion();
            manager.insertar(checkeado, codigo, codigoProceso);

        }

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

}

From source file:com.ibm.bluemix.hack.image.ImageEvaluator.java

@SuppressWarnings("unchecked")
public JSONObject analyzeImage(byte[] buf) throws IOException {

    JSONObject imageProcessingResults = new JSONObject();

    JSONObject creds = VcapServicesHelper.getCredentials("watson_vision_combined", null);

    String baseUrl = creds.get("url").toString();
    String apiKey = creds.get("api_key").toString();
    String detectFacesUrl = baseUrl + "/v3/detect_faces?api_key=" + apiKey + "&version=2016-05-20";
    String classifyUrl = baseUrl + "/v3/classify?api_key=" + apiKey + "&version=2016-05-20";

    OkHttpClient client = new OkHttpClient();

    RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
            .addFormDataPart("images_file", "sample.jpg", RequestBody.create(MediaType.parse("image/jpg"), buf))
            .build();/* w  ww  .  j  a v a2s  .  co m*/

    Request request = new Request.Builder().url(detectFacesUrl).post(requestBody).build();

    Response response = client.newCall(request).execute();
    String result = response.body().string();

    JSONParser jsonParser = new JSONParser();

    try {
        JSONObject results = (JSONObject) jsonParser.parse(result);
        // since we only process one image at a time, let's simplfy the json 
        // we send to the JSP.
        JSONArray images = (JSONArray) results.get("images");
        if (images != null && images.size() > 0) {
            JSONObject firstImage = (JSONObject) images.get(0);
            JSONArray faces = (JSONArray) firstImage.get("faces");
            imageProcessingResults.put("faces", faces);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // now request classification
    request = new Request.Builder().url(classifyUrl).post(requestBody).build();

    response = client.newCall(request).execute();
    result = response.body().string();
    try {
        JSONObject results = (JSONObject) jsonParser.parse(result);
        // since we only process one image at a time, let's simplfy the json 
        // we send to the JSP.
        JSONArray images = (JSONArray) results.get("images");
        if (images != null && images.size() > 0) {
            JSONObject firstImage = (JSONObject) images.get(0);
            JSONArray classifiers = (JSONArray) firstImage.get("classifiers");
            imageProcessingResults.put("classifiers", classifiers);
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return imageProcessingResults;
}

From source file:com.des.paperbase.ManageData.java

public void delete(String Tablename, Map<String, Object> value, String FilterType)
        throws ParseException, IOException {
    String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json");
    List<Integer> ListDelete = new LinkedList<Integer>();
    if (!data.equalsIgnoreCase("{\"data\":[]}")) {
        JSONObject json = (JSONObject) new JSONParser().parse(data);
        JSONArray OldValue = (JSONArray) json.get("data");
        for (int s = 0; s < OldValue.size(); s++) {
            JSONObject record = (JSONObject) OldValue.get(s);
            if (MappingRecordAndKey(value, record, FilterType)) {
                ListDelete.add(s);//from   w  w w .  j a va 2s .co  m
            }
        }
        for (int i = ListDelete.size() - 1; i >= 0; i--) {
            System.out.print(ListDelete.get(i) + " ");
            OldValue.remove(ListDelete.get(i).intValue());
        }
        JSONObject table = new JSONObject();
        table.put("data", OldValue);
        g.writefile(table.toJSONString(), PATH_FILE + "\\" + Tablename + ".json");
    }

}

From source file:biomine.bmvis2.crawling.CrawlerFetch.java

public void update() throws IOException {

    status = URLUtils.getURLContents(statusUrl);
    statusObject = (JSONObject) JSONValue.parse(status);
    JSONObject obj = (JSONObject) JSONValue.parse(status);
    JSONArray errors = ((JSONArray) obj.get("errors"));

    d("obj = " + obj);
    int age = ((Long) obj.get("age")).intValue();
    d("age = " + age);

    lastage = age;/*from www.j  av a2 s .  c  o  m*/
    messages.clear();
    for (Object o : errors) {
        JSONObject error = (JSONObject) o;
        JSONArray mesarr = (JSONArray) error.get("messages");

        for (int i = 0; i < mesarr.size(); i++) {
            String err = mesarr.get(i).toString();
            messages.add(err);
            d("err = " + err);
        }
    }

    JSONArray mesarr = (JSONArray) obj.get("messages");

    for (int i = 0; i < mesarr.size(); i++) {
        String err = mesarr.get(i).toString();
        messages.add(err);
        d("err = " + err);
    }
}

From source file:net.phyloviz.upgmanjcore.json.JsonSchemaValidator.java

private void createOrder(JSONArray orderObj) {
    orderList = new String[orderObj.size()];
    for (int i = 0; i < orderObj.size(); i++) {
        orderList[i] = (String) orderObj.get(i);
    }// w w  w .ja va  2s  .  com
}

From source file:com.des.paperbase.ManageData.java

public void update(String Tablename, Map<String, Object> Filter, Map<String, Object> updateValue,
        String FilterType) throws IOException, ParseException {
    String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json");
    JSONObject json = (JSONObject) new JSONParser().parse(data);
    List<String> keySet = g.getKeyFromMap(updateValue);
    if (!data.equalsIgnoreCase("{\"data\":[]}")) {
        JSONArray newValue = new JSONArray();
        JSONArray OldValue = (JSONArray) json.get("data");
        for (int s = 0; s < OldValue.size(); s++) {
            JSONObject record = (JSONObject) OldValue.get(s);
            if (MappingRecordAndKey(Filter, record, FilterType)) {
                for (int i = 0; i < keySet.size(); i++) {
                    System.out.println("replace : " + keySet.get(i) + "  to " + updateValue.get(keySet.get(i)));
                    record.replace(keySet.get(i), updateValue.get(keySet.get(i)));
                }//from   www  . java2s  . c  om

            }
            newValue.add(record);
        }
        json.put("data", newValue);
        System.out.println(json.toJSONString());
        g.writefile(json.toJSONString(), PATH_FILE + "\\" + Tablename + ".json");
    } else {
        g.writefile(data, PATH_FILE + "\\" + Tablename + ".json");
    }

}

From source file:com.des.paperbase.ManageData.java

public List<Map<String, Object>> select(String Tablename, Map<String, Object> value, String FilterType)
        throws ParseException {
    String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json");
    System.out.println(PATH_FILE + "\\" + Tablename + ".json");
    JSONArray output = new JSONArray();
    JSONObject json = (JSONObject) new JSONParser().parse(data);
    List<Map<String, Object>> result = new LinkedList<Map<String, Object>>();
    GenerateFile g = new GenerateFile();
    if (!data.equalsIgnoreCase("{\"data\":[]}")) {
        JSONArray OldValue = (JSONArray) json.get("data");
        for (int s = 0; s < OldValue.size(); s++) {
            JSONObject record = (JSONObject) OldValue.get(s);
            if (MappingRecordAndKey(value, record, FilterType)) {
                List<String> Listkey = g.getKeyFromJSONArray(record.keySet());
                Map<String, Object> Maprecord = new HashMap<String, Object>();
                for (int i = 0; i < Listkey.size(); i++) {
                    System.out.println(Listkey.get(i) + "," + record.get(Listkey.get(i)));
                    Maprecord.put(Listkey.get(i), record.get(Listkey.get(i)));
                }//from  w  w  w  . ja  v a2s.c om
                result.add(Maprecord);
            }
        }
    } else {

    }
    return result;
}

From source file:gessi.ossecos.graph.GraphModel.java

public static void IStarJsonToGraphFile(String iStarModel, String layout, String typeGraph)
        throws ParseException {
    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(iStarModel);

    JSONArray jsonArrayNodes = (JSONArray) jsonObject.get("nodes");
    JSONArray jsonArrayEdges = (JSONArray) jsonObject.get("edges");
    String modelType = jsonObject.get("modelType").toString();

    // System.out.println(modelType);
    // System.out.println(jsonArrayNodes.toJSONString());
    // System.out.println(jsonArrayEdges.toJSONString());

    System.out.println(jsonObject.toJSONString());

    Hashtable<String, String> nodesHash = new Hashtable<String, String>();
    Hashtable<String, String> boundaryHash = new Hashtable<String, String>();
    Hashtable<String, Integer> countNodes = new Hashtable<String, Integer>();
    ArrayList<String> boundaryItems = new ArrayList<String>();
    ArrayList<String> actorItems = new ArrayList<String>();
    GraphViz gv = new GraphViz();
    gv.addln(gv.start_graph());/*from  w  w  w. ja  va2  s. c o  m*/

    String nodeType;
    String nodeName;
    String nodeBoundary;
    for (int i = 0; i < jsonArrayNodes.size(); i++) {

        jsonObject = (JSONObject) jsonArrayNodes.get(i);
        nodeName = jsonObject.get("name").toString().replace(" ", "_");
        // .replace("(", "").replace(")", "");
        nodeName = nodeName.replaceAll("[\\W]|`[_]", "");
        nodeType = jsonObject.get("elemenType").toString();
        nodeBoundary = jsonObject.get("boundary").toString();
        // TODO: Verify type of diagram
        // if (!nodeType.equals("actor") & !nodeBoundary.equals("boundary"))
        // {
        if (countNodes.get(nodeName) == null) {
            countNodes.put(nodeName, 0);
        } else {
            countNodes.put(nodeName, countNodes.get(nodeName) + 1);
            nodeName += "_" + countNodes.put(nodeName, 0);

        }
        gv.addln(renderNode(nodeName, nodeType));

        // }

        nodesHash.put(jsonObject.get("id").toString(), nodeName);
        boundaryHash.put(jsonObject.get("id").toString(), nodeBoundary);
        if (nodeType.equals("actor")) {
            actorItems.add(nodeName);
        }
    }

    String edgeType = "";
    String source = "";
    String target = "";
    String edgeSubType = "";
    int subgraphCount = 0;
    boolean hasCluster = false;
    nodeBoundary = "na";
    String idSource;
    String idTarget;
    for (int i = 0; i < jsonArrayEdges.size(); i++) {

        jsonObject = (JSONObject) jsonArrayEdges.get(i);
        edgeSubType = jsonObject.get("linksubtype").toString();
        edgeType = renderEdge(edgeSubType, jsonObject.get("linktype").toString());
        idSource = jsonObject.get("source").toString();
        idTarget = jsonObject.get("target").toString();
        source = nodesHash.get(idSource);
        target = nodesHash.get(idTarget);

        if (!boundaryHash.get(idSource).toString().equals("boundary")
                && !boundaryHash.get(idTarget).toString().equals("boundary")) {
            if (!boundaryHash.get(idSource).toString().equals(nodeBoundary)) {
                nodeBoundary = boundaryHash.get(idSource).toString();
                if (hasCluster) {
                    gv.addln(gv.end_subgraph());
                    hasCluster = false;

                } else {
                    hasCluster = true;
                }
                gv.addln(gv.start_subgraph(subgraphCount));
                gv.addln(actorItems.get(subgraphCount++));
                gv.addln("style=filled;");
                gv.addln("color=lightgrey;");

            }
            gv.addln(source + "->" + target + edgeType);

        } else {

            boundaryItems.add(source + "->" + target + edgeType);

        }

    }
    if (subgraphCount > 0) {
        gv.addln(gv.end_subgraph());
    }
    for (String boundaryE : boundaryItems) {
        gv.addln(boundaryE);
    }
    gv.addln(gv.end_graph());

    String type = typeGraph;
    // String type = "dot";
    // String type = "fig"; // open with xfig
    // String type = "pdf";
    // String type = "ps";
    // String type = "svg"; // open with inkscape
    // String type = "png";
    // String type = "plain";

    String repesentationType = layout;
    // String repesentationType= "neato";
    // String repesentationType= "fdp";
    // String repesentationType= "sfdp";
    // String repesentationType= "twopi";
    // String repesentationType= "circo";

    // //File out = new File("/tmp/out"+gv.getImageDpi()+"."+ type); //
    // Linux
    File out = new File("Examples/out." + type); // Windows
    gv.writeGraphToFile(gv.getGraph(gv.getDotSource(), type, repesentationType), out);

}