List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:com.shazam.dataengineering.pipelinebuilder.Deployment.java
public Deployment(JSONObject obj) { this.username = (String) obj.get("username"); this.status = (Boolean) obj.get("status"); this.pipelineId = (String) obj.get("pipelineId"); this.date = new Date((Long) obj.get("date")); JSONArray messageArray = (JSONArray) obj.get("messages"); this.messages = new ArrayList<String>(); for (int i = 0; i < messageArray.size(); i++) { this.messages.add((String) messageArray.get(i)); }//w w w.ja va 2s . c om }
From source file:info.usbo.skypetwitter.VK.java
VK(String line) throws ParseException { JSONObject json2 = (JSONObject) new JSONParser().parse(line); id = Long.parseLong(json2.get("id").toString()); text = json2.get("text").toString(); if ("".equals(text)) { if (json2.get("copy_history") != null) { JSONArray json3 = (JSONArray) new JSONParser().parse(json2.get("copy_history").toString()); if (json3.size() > 0) { JSONObject json4 = (JSONObject) new JSONParser().parse(json3.get(0).toString()); text = json4.get("text").toString(); }//from w w w .j a v a2 s.c o m } else { text = ""; } } date = new Date(Long.parseLong(json2.get("date").toString()) * 1000); attachment = findAttachment(json2); }
From source file:com.mstiles92.plugins.stileslib.updates.UpdateChecker.java
/** * The task to be run by the Bukkit scheduler that finds the latest published version on BukkitDev. *///ww w .ja v a 2 s. c o m @Override public void run() { try { URL url = new URL("https://api.curseforge.com/servermods/files?projectIds=" + curseProjectId); URLConnection connection = url.openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(10000); connection.addRequestProperty("User-Agent", plugin.getName() + " (by mstiles92)"); InputStream stream = connection.getInputStream(); JSONParser parser = new JSONParser(); Object o = parser.parse(new InputStreamReader(stream)); stream.close(); JSONArray array = (JSONArray) o; if (array.size() > 0) { JSONObject latest = (JSONObject) array.get(array.size() - 1); latestVersion = (String) latest.get("name"); latestVersion = latestVersion.substring(1, latestVersion.length()); updateAvailable = isNewerVersion(latestVersion); if (updateAvailable) { plugin.getLogger().info("Update available! New version: " + latestVersion); plugin.getLogger() .info("More information available at http://dev.bukkit.org/bukkit-plugins/" + slug); } } } catch (IOException | ParseException | ClassCastException e) { plugin.getLogger() .info("Unable to check for updates. Will try again later. Error message: " + e.getMessage()); } }
From source file:io.fabric8.jolokia.assertions.JSONArrayAssert.java
/** * Returns the value at the given index//from www . ja v a2s. c om */ public Object value(int index) { JSONArray array = get(); assertThat(array.size()).as("size of array").isGreaterThan(index); return array.get(index); }
From source file:io.personium.test.jersey.cell.ctl.ExtCellLinkTest.java
/** * ?????./*w w w . ja v a 2 s . c om*/ */ @Before public final void before() { if (roleUri == null) { TResponse response = Http.request("role-list.txt") .with("token", AbstractCase.MASTER_TOKEN_NAME).with("cellPath", CELL_NAME) .returns().statusCode(HttpStatus.SC_OK); JSONObject d = (JSONObject) response.bodyAsJson().get("d"); JSONArray results = (JSONArray) d.get("results"); String name = (String) ((JSONObject) results.get(0)).get("Name"); String boxName = (String) ((JSONObject) results.get(0)).get("_Box.Name"); if (boxName == null) { roleKey = "Name='" + name + "',_Box.Name=null"; } else { roleKey = "Name='" + name + "',_Box.Name='" + boxName + "'"; } roleUri = UrlUtils.cellCtlWithoutSingleQuote(CELL_NAME, ENTITY_SET_ROLE, roleKey); } }
From source file:logic.ZybezItemListing.java
private void setItemOffers() { JSONObject o = (JSONObject) JSONValue.parse(listingJsonString); String offerString = o.get("offers").toString(); JSONArray array = (JSONArray) JSONValue.parse(offerString); numOffers = array.size();// w w w . j av a 2 s .c om for (int i = 0; i < numOffers; i++) { JSONObject o2 = (JSONObject) JSONValue.parse(array.get(i).toString()); ZybezOffer z = new ZybezOffer(itemID, o2.get("selling").toString(), o2.get("quantity").toString(), o2.get("price").toString(), itemName, o2.get("rs_name").toString(), o2.get("notes").toString()); offerList.add(z); } }
From source file:buspathcontroller.JSONFileParser.java
public void generateRouteStopsAndPath() { JSONParser parser = new JSONParser(); ArrayList<String> routeList = new ArrayList<String>(); try {/*from w ww . j av a2 s .c o m*/ FileReader reader = new FileReader("/Users/Zhaowei/Desktop/BusPath/allRoutes.txt"); BufferedReader br = new BufferedReader(reader); String line; while ((line = br.readLine()) != null) { String routeName = line.split(";")[1]; routeList.add(routeName); } br.close(); reader.close(); Iterator<String> it = routeList.iterator(); while (it.hasNext()) { String routeName = it.next(); PrintWriter writer = new PrintWriter( "/Users/Zhaowei/Desktop/BusPath/routeInfo/stops/" + routeName + ".txt"); Object obj = parser.parse( new FileReader("/Users/Zhaowei/Desktop/BusPath/RawJSON/route/" + routeName + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONObject route = (JSONObject) jsonObject.get("route"); JSONArray directions = (JSONArray) route.get("directions"); for (int i = 0; i < directions.size(); i++) { JSONObject direction = (JSONObject) directions.get(i); writer.println(direction.get("direction")); JSONArray stops = (JSONArray) direction.get("stops"); Iterator iter = stops.iterator(); while (iter.hasNext()) { JSONObject stop = (JSONObject) iter.next(); writer.println(stop.get("stopnumber") + ";" + stop.get("stoptitle") + ";" + stop.get("stoplat") + ";" + stop.get("stoplng")); } } writer.close(); } } catch (Exception e) { System.out.println(e); } }
From source file:ejb.services.MarvelService.java
@GET @Path("/listaPopup/{login}") @Produces({ "application/text" }) public String listaPopup(@PathParam("login") final String login) { List<Usuario> usuarios = new ArrayList<Usuario>(); usuarios = usuarioBean.listLogin(login); Usuario u = usuarios.get(0);//from w w w .j a v a 2 s . c om String apikey = "62cc7f7bd41e3346a1af737e0449428b"; String privatekey = "a9e5cccf7acc7f9ce2555471b5b6fc51d5725df6"; String urlbase = "http://gateway.marvel.com/v1/public/characters"; //Criao de um timestamp Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyyhhmmss"); String ts = sdf.format(date); //Criao do HASH String hashStr = hash.MD5(ts + privatekey + apikey); String uri; String nomeAvatar = u.getAvatar(); //Converso necessria para aplicar o %20 no nome //String[] name = nomeAvatar.split(" "); //String nomeOk = name[0] + "%20" + name[1]; nomeAvatar.replace(" ", "%20"); //url de consulta uri = urlbase + "?nameStartsWith=" + nomeAvatar + "&ts=" + ts + "&apikey=" + apikey + "&hash=" + hashStr; //System.out.println(uri); try { HttpClient cliente = HttpClients.createDefault(); //HttpHost proxy = new HttpHost("172.16.0.10", 3128, "http"); //RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); HttpGet httpget = new HttpGet(uri); // httpget.setConfig(config); HttpResponse response = cliente.execute(httpget); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); Header[] h = response.getAllHeaders(); for (Header head : h) { System.out.println(head.getValue()); } HttpEntity entity = response.getEntity(); StringReader readerLine = null; if (entity != null) { InputStream instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder out = new StringBuilder(); String line; line = reader.readLine(); readerLine = new StringReader(line); reader.close(); instream.close(); JSONObject jsonObject = (JSONObject) new JSONParser().parse(line); JSONObject jsonObjectData = (JSONObject) jsonObject.get("data"); JSONArray lang = (JSONArray) jsonObjectData.get("results"); JSONObject jsonObjectDados = (JSONObject) lang.get(0); JSONObject jsonPath = (JSONObject) jsonObjectDados.get("thumbnail"); String nomeMarvel = (String) jsonObjectDados.get("name"); String descricao = (String) jsonObjectDados.get("description"); String urlImg = (String) jsonPath.get("path"); String result = "<p>Personagem: " + nomeMarvel + "</p> <br />"; result += "<p>Descrio: " + descricao + "</p> <br />"; result += "<img src='" + urlImg + ".jpg' alt='foto'/ height='200' width='200'>"; return result; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.noelportugal.amazonecho.AmazonEchoApi.java
public String getLatestTodo() throws IOException { String output = httpGet("/api/todos?type=TASK&size=1"); // System.out.println(output); // Parse JSON Object obj = JSONValue.parse(output); JSONObject jsonObject = (JSONObject) obj; JSONArray values = (JSONArray) jsonObject.get("values"); JSONObject item = (JSONObject) values.get(0); //System.out.println(item); // Get text and itemId String text = item.get("text").toString(); String itemId = item.get("itemId").toString(); if (!checkItemId(itemId)) { return text; } else {// w w w . j a v a 2 s.c o m return null; } }
From source file:Json.JsonCodes.java
public void jsonRead(String patchName) throws IOException, ParseException { JSONParser parser = new JSONParser(); JSONObject object = (JSONObject) parser.parse(new FileReader(patchName)); JSONArray arr = new JSONArray(); this.patch = (String) object.get("patch"); arr = (JSONArray) object.get("page"); for (int i = 0; i < arr.size(); i++) { this.pageList.add((String) arr.get(i)); }//from w w w . j a va 2 s .com System.out.println("Json.JsonWrite.jsonRead()"); }