Example usage for org.json.simple JSONArray get

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

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

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  ww  w . ja  va 2 s . c  om*/
    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:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java

public List<Deployment> getAll() {
    JSONArray deployments = (JSONArray) log.get(ROOT);
    ArrayList<Deployment> deploymentArrayList = new ArrayList<Deployment>();
    for (int i = 0; i < deployments.size(); i++) {
        deploymentArrayList.add(new Deployment((JSONObject) deployments.get(i)));
    }/*  www .  j  a v a 2  s . c  o m*/

    return deploymentArrayList;
}

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();/*w ww  . j a v  a  2s .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:ServiceController.java

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

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

    try {/*  w  w  w.jav  a  2 s  .  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:info.usbo.skypetwitter.VK.java

private String findAttachment(JSONObject js) throws ParseException {
    String att = "";
    System.out.println("att0" + js.get("id").toString());
    if (js.get("attachments") != null) {
        System.out.println("att1");
        JSONArray attach = (JSONArray) new JSONParser().parse(js.get("attachments").toString());
        if (attach.size() > 0) {
            System.out.println("att2");
            JSONObject attach1 = (JSONObject) new JSONParser().parse(attach.get(0).toString());
            if (attach1.get("type") != null && "photo".equals(attach1.get("type").toString())) {
                System.out.println("att3");
                JSONObject photo = (JSONObject) new JSONParser().parse(attach1.get("photo").toString());
                if (photo.get("photo_604") != null) {
                    att = photo.get("photo_604").toString();
                }//from  ww  w .  j ava2s  .  c  o m
            }
        }
    }
    return att;
}

From source file:io.github.apfelcreme.LitePortals.Bungee.LitePortals.java

/**
 * returns the name of a player/*from w ww  .ja  va2s  .c o m*/
 *
 * @param uuid a players uuid
 * @return his name
 */
public String getNameByUUID(UUID uuid) {
    if (uuidCache.containsValue(uuid)) {
        for (Map.Entry<String, UUID> entry : uuidCache.entrySet()) {
            if (entry.getValue().equals(uuid)) {
                return entry.getKey();
            }
        }
    } else if (getProxy().getPluginManager().getPlugin("UUIDDB") != null) {
        String name = UUIDDB.getInstance().getStorage().getNameByUUID(uuid);
        uuidCache.put(name.toUpperCase(), uuid);
        return name;
    } else {
        try {
            URL url = new URL(LitePortalsConfig.getInstance().getConfiguration().getString("nameUrl")
                    .replace("{0}", uuid.toString().replace("-", "")));
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuilder json = new StringBuilder();
            int read;
            while ((read = in.read()) != -1) {
                json.append((char) read);
            }
            Object obj = new JSONParser().parse(json.toString());
            JSONArray jsonArray = (JSONArray) obj;
            String name = (String) ((JSONObject) jsonArray.get(jsonArray.size() - 1)).get("name");
            uuidCache.put(name.toUpperCase(), uuid);
            return name;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    return null;
}

From source file:com.sourav.apps.PiMessageFetcher.java

@Override
public void run() {
    while (running) {
        try {/*from  ww  w  .  java2s .  c  om*/
            String rawJSON = client.get().getText();
            JSONArray messages = (JSONArray) JSONValue.parse(rawJSON);
            PiChatterWindow window = PiChatterWindow.getWindow();

            for (int i = 0; i < messages.size(); i++) {
                JSONObject message = (JSONObject) messages.get(i);
                String from = (String) message.get("from");
                String time = (String) message.get("time");
                String body = (String) message.get("data");
                body = PiCodec.decode(body);

                String str = String.format(" %s: %s\t (sent at: %s)", from, body, time);
                window.appendChat(str);
            }

            if (messages.size() > 0) {
                menuref.setNotification();
            }

        } catch (IOException iox) {
            iox.printStackTrace();
        }
        try {
            Thread.sleep(600);
        } catch (InterruptedException iox) {
            iox.printStackTrace();
        }
    }
}

From source file:guestbook.Entity.java

public String getValue(String p) {
    if (statements == null)
        return null;
    Set s = statements.keySet();//  w  w w  .  j  a v a  2s .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:info.mallmc.framework.util.ProfileLoader.java

private void addProperties(GameProfile profile) {
    String uuid = getUUID(skinOwner);
    try {//from www . java 2  s . c o m
        // Get the name from SwordPVP
        URL url = new URL(
                "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
        URLConnection uc = url.openConnection();
        uc.setUseCaches(false);
        uc.setDefaultUseCaches(false);
        uc.addRequestProperty("User-Agent", "Mozilla/5.0");
        uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate");
        uc.addRequestProperty("Pragma", "no-cache");

        // Parse it
        String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(json);
        JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties");
        for (int i = 0; i < properties.size(); i++) {
            try {
                JSONObject property = (JSONObject) properties.get(i);
                String name = (String) property.get("name");
                String value = (String) property.get("value");
                String signature = property.containsKey("signature") ? (String) property.get("signature")
                        : null;
                if (signature != null) {
                    profile.getProperties().put(name, new Property(name, value, signature));
                } else {
                    profile.getProperties().put(name, new Property(value, name));
                }
            } catch (Exception e) {
                L.ogError(LL.ERROR, Trigger.LOAD, "Failed to apply auth property",
                        "Failed to apply auth property");
            }
        }
    } catch (Exception e) {
        ; // Failed to load skin
    }
}

From source file:JavaCloud.Api.java

public ArrayList<String> functionList() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("token", token);
    JSONArray jsonfuncs = (JSONArray) Utils.request(address, "/api/api/list_functions/", object);
    ArrayList<String> functions = new ArrayList<String>();
    for (int i = 0; i < jsonfuncs.size(); i++) {
        functions.add(jsonfuncs.get(i).toString());
    }//  w w w . j av  a 2 s.  c o  m

    return functions;
}