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:mediasearch.twitter.TwitterService.java

private ArrayList<TwitterTweet> parseJsonIntoTweets(JSONObject object) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(String.class, new NullJsonStringConverter());
    gsonBuilder.serializeNulls();//from  w  w w .  j a va 2 s.  com
    Gson gson = gsonBuilder.create();

    JSONArray array = (JSONArray) object.get("statuses");
    for (int i = 0; i < array.size(); i++) {
        JSONObject jSONObject = (JSONObject) array.get(i);
        TwitterTweet tweet = gson.fromJson(jSONObject.toString(), TwitterTweet.class);
        ret.add(tweet);
    }

    return ret;
}

From source file:lockers.FrameCobro.java

private void getAvailableLockers() {
    JSONArray array = Utils.getJSONArrayFromURL("http://127.0.0.1:8000/Lockers_Search/?status=0&format=json");

    System.out.println(array.size());
    if (array.size() == 0) {
        this.jLblAvailableLockers.setText("No hay disponibilidad");
    } else {// ww w.  ja v  a 2  s . co  m
        this.jLblAvailableLockers.setText("La cantidad de lockers disponibles es :" + array.size());
        for (Object array1 : array) {
            JButton nuevo = new JButton();
            JSONObject obj2 = (JSONObject) array1;
            nuevo.setText(obj2.get("locker_name").toString());
            nuevo.setVisible(true);
            this.jPanel2.add(nuevo);
        }
    }
}

From source file:ServiceController.java

public Service serviceResponse(String hostid, PutMethod putMethod, String name) {
    JSONParser parser = new JSONParser();

    String loginResponse = "";
    HttpClient client = new HttpClient();

    try {//w ww  .  jav a2s.  co  m
        client.executeMethod(putMethod); // send to request to the zabbix api
        loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response
        Object obj = parser.parse(loginResponse);
        JSONObject obj2 = (JSONObject) obj;
        String jsonrpc = (String) obj2.get("jsonrpc");

        JSONArray array = (JSONArray) obj2.get("result");

        for (int i = 0; i < array.size(); i++) {
            JSONObject tobj = (JSONObject) array.get(i);
            if (!tobj.get("hostid").equals(hostid))
                continue;
            if (comparision(name, "availability", tobj, AVAILABILITY))
                return getService(tobj, hostid, AVAILABILITY);
            else
                continue;
        }
    } catch (HttpException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException pe) {
        System.out.println("Error");
    }

    return new Service(
            "Error: please provide the appropriate input parameters of the metric you are looking for its corresponding monitoring data:");
}

From source file:net.phyloviz.upgma.json.UPGMAItemFactory.java

private Map<Integer, UPGMALeafNode> createLeafs(TypingData<? extends AbstractProfile> td, JSONArray leafsArr) {

    Map<Integer, UPGMALeafNode> leafs = new HashMap(leafsArr.size());
    Map<String, Profile> profiles = new HashMap(td.size());

    for (Iterator<? extends AbstractProfile> it = td.iterator(); it.hasNext();) {
        Profile p = it.next();//from ww  w  . ja  va 2s  .  co  m
        profiles.put(p.getID(), p);
    }
    for (Iterator<JSONObject> it = leafsArr.iterator(); it.hasNext();) {
        JSONObject l = it.next();
        String p = (String) l.get("profile");
        Integer uid = (int) (long) l.get("uid");
        leafs.put(uid, new UPGMALeafNode(uid, profiles.get(p), td.size(), uid));
    }

    return leafs;
}

From source file:edu.ncsu.epc.models.GetInfo.java

public ApartmentInfo parseJSON(String response, String addr) {
    ApartmentInfo aptInfo = null;//from  w ww.  j a va 2 s  . co  m
    try {
        JSONObject json = (JSONObject) new JSONParser().parse(response);
        JSONArray jsonArray = (JSONArray) new JSONParser().parse(json.get("collection").toString());
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject json2 = (JSONObject) new JSONParser().parse(jsonArray.get(i).toString());
            if (addr.startsWith(json2.get("address").toString())) {
                aptInfo = new ApartmentInfo();
                aptInfo.addr = json2.get("address").toString();
                if (json2.get("city") != null)
                    aptInfo.city = json2.get("city").toString();
                if (json2.get("state") != null)
                    aptInfo.state = json2.get("state").toString();
                if (json2.get("bedrooms") == null) {
                    JSONArray jsonArray1 = (JSONArray) new JSONParser()
                            .parse(json2.get("latest_prices").toString());
                    JSONObject jsonlatest_price = (JSONObject) new JSONParser()
                            .parse(jsonArray1.get(0).toString());
                    aptInfo.noOfBedrooms = Double.parseDouble(jsonlatest_price.get("bedrooms").toString());
                    aptInfo.rent = Double.parseDouble(jsonlatest_price.get("rent").toString());
                } else {
                    aptInfo.noOfBedrooms = Double.parseDouble(json2.get("bedrooms").toString());
                    aptInfo.rent = Double.parseDouble(json2.get("rent").toString());
                }
                if (json2.get("rent") != null)
                    aptInfo.rent = Double.parseDouble(json2.get("rent").toString());
                aptInfo.zip = (String) json2.get("zip_code");
                if (json2.get("year_built") != null)
                    aptInfo.year_built = Double.parseDouble(json2.get("year_built").toString());

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return aptInfo;
}

From source file:com.n1t3slay3r.empirecraft.main.Update.java

/**
 * Query the API to find the latest approved file's details.
 *//*  w ww. j a v  a  2  s.  c om*/
public void query() {
    URL url;

    try {
        // Create the URL to query using the project's ID
        url = new URL(API_HOST + API_QUERY + projectID);
    } catch (MalformedURLException e) {
        return;
    }

    try {
        // Open a connection and query the project
        URLConnection conn = url.openConnection();

        if (apiKey != null) {
            // Add the API key to the request if present
            conn.addRequestProperty("X-API-Key", apiKey);
        }

        // Add the user-agent to identify the program
        conn.addRequestProperty("User-Agent", "ServerModsAPI-Example (by Gravity)");

        // Read the response of the query
        // The response will be in a JSON format, so only reading one line is necessary.
        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String response = reader.readLine();

        // Parse the array of files from the query's response
        JSONArray array = (JSONArray) JSONValue.parse(response);

        if (array.size() > 0) {
            // Get the newest file's details
            JSONObject latest = (JSONObject) array.get(array.size() - 1);

            // Get the version's title
            String versionName = (String) latest.get(API_NAME_VALUE);

            // Get the version's link
            String versionLink = (String) latest.get(API_LINK_VALUE);

            // Get the version's release type
            String versionType = (String) latest.get(API_RELEASE_TYPE_VALUE);

            // Get the version's file name
            String versionFileName = (String) latest.get(API_FILE_NAME_VALUE);

            // Get the version's game version
            String versionGameVersion = (String) latest.get(API_GAME_VERSION_VALUE);

            if (playername != null) {
                Bukkit.getPlayer(UUID.fromString(playername))
                        .sendMessage(ChatColor.YELLOW + "The latest version of " + ChatColor.GOLD
                                + versionFileName + ChatColor.YELLOW + " is " + ChatColor.GOLD + versionName
                                + ChatColor.YELLOW + ", a " + ChatColor.GOLD + versionType.toUpperCase()
                                + ChatColor.YELLOW + " for " + ChatColor.GOLD + versionGameVersion
                                + ChatColor.YELLOW + ", available at: " + ChatColor.GOLD + versionLink);
            } else {
                System.out.println("The latest version of " + versionFileName + " is " + versionName + ", a "
                        + versionType.toUpperCase() + " for " + versionGameVersion + ", available at: "
                        + versionLink);
            }
        }
    } catch (IOException e) {
    }
}

From source file:JavaCloud.Cloud.java

public ArrayList<Token> tokenList() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("login", login);
    object.put("pw_hash", Utils.calcHash(password, seed));

    JSONArray jsontokens = (JSONArray) Utils.request(address, "/user/token/get_list/", object);

    ArrayList<Token> tokens = new ArrayList<Token>();
    for (int i = 0; i < jsontokens.size(); i++) {
        tokens.add(new Token(address, login, password, seed, (JSONObject) jsontokens.get(i)));
    }// w  w w  . ja v  a2s . com

    return tokens;
}

From source file:kr.co.bitnine.octopus.testutils.MemoryDatabaseTest.java

@Test
public void testImport() throws Exception {
    MemoryDatabase memDb = new MemoryDatabase("sample");
    memDb.start();//from   w ww.  j  av a  2  s.  c om

    final String jsonFileName = "/sample.json";
    memDb.importJSON(getClass(), jsonFileName);

    JSONParser jsonParser = new JSONParser();
    JSONArray tables = (JSONArray) jsonParser
            .parse(new InputStreamReader(getClass().getResourceAsStream(jsonFileName)));
    assertEquals(2, tables.size());

    Connection conn = memDb.getConnection();
    Statement stmt = conn.createStatement();

    JSONObject employee = (JSONObject) tables.get(0);
    ResultSet rs = stmt.executeQuery("SELECT * FROM \"employee\"");
    verifyTableEquals(employee, rs);
    rs.close();

    JSONObject team = (JSONObject) tables.get(1);
    rs = stmt.executeQuery("SELECT * FROM \"team\"");
    verifyTableEquals(team, rs);
    rs.close();

    stmt.close();
    conn.close();

    memDb.stop();
}

From source file:JavaCloud.Api.java

public ArrayList<VM> vmList() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("token", token);
    JSONArray jsonvms = (JSONArray) Utils.request(address, "/api/vm/get_list/", object);
    ArrayList<VM> vms = new ArrayList<VM>();
    for (int i = 0; i < jsonvms.size(); i++) {
        vms.add(new VM(address, token, (JSONObject) jsonvms.get(i)));
    }//from  ww  w  .  j  a  va2s.c o m

    return vms;
}

From source file:net.phyloviz.goeburst.tree.GOeBurstMSTItemFactory.java

private Map<Integer, GOeBurstNode> getNodes(Map<String, GOeBurstNode> td, JSONArray onodes) {

    Map<Integer, GOeBurstNode> nodes = new HashMap<>();
    for (Iterator<JSONObject> nIt = onodes.iterator(); nIt.hasNext();) {
        JSONObject node = nIt.next();/*from ww w . j  a v a2s.  c o m*/
        Integer uid = (int) (long) node.get("id");
        String profile = (String) node.get("profile");
        JSONArray group_lvs = (JSONArray) node.get("group-lvs");

        GOeBurstNode n = td.get(profile);
        n.lv = new int[group_lvs.size()];
        for (int i = 0; i < group_lvs.size(); i++)
            n.lv[i] = (int) (long) group_lvs.get(i);

        nodes.put(uid, n);

    }
    return nodes;
}