List of usage examples for org.json.simple JSONArray size
public int size()
From source file:iracing.webapi.SessionResultDriverLapsParser.java
static SessionResultDriverLaps parse(String json) { JSONParser parser = new JSONParser(); SessionResultDriverLaps output = null; try {/*from ww w . j a v a 2 s . c om*/ JSONObject root = (JSONObject) parser.parse(json); output = new SessionResultDriverLaps(); JSONObject details = (JSONObject) root.get("details"); output.setLapsForSolo(getInt(details, "nlapsforsolo")); output.setBestNLapsNumber(getInt(details, "bestnlapsnum")); output.setSeasonShortName(getString(details, "seasonShortName", true)); output.setMaximumLicenseLevel(getInt(details, "maxLicenseLevel")); output.setDriverName(getString(details, "displayname", true)); output.setSeasonName(getString(details, "seasonName", true)); output.setSeriesName(getString(details, "seriesName", true)); output.setSeriesShortName(getString(details, "seriesShortName", true)); output.setSessionId(getLong(details, "sessionId")); output.setSubSessionId(getLong(details, "subSessionId")); output.setCarNumber(getString(details, "carNum")); output.setCarId(getInt(details, "carid")); output.setEventTypeId(getInt(details, "eventtype")); output.setEventTypeName(getString(details, "eventTypeName", true)); output.setBestQualifyingLapAt(getInt(details, "bestQualLapAt")); output.setBestQualifyingLapNumber(getInt(details, "bestQualLapNum")); output.setBestLapNumber(getInt(details, "bestLapNum")); output.setBestNLapsTime(getInt(details, "bestNLapsTime")); output.setLapsForQualifying(getInt(details, "nlapsforqual")); output.setBestQualifyingLapTime(getLong(details, "bestQualLapTime")); output.setTrackId(getInt(details, "trackID")); output.setTrackName(getString(details, "trackName", true)); output.setTrackConfigName(getString(details, "trackConfig", true)); output.setEventDate(new Date(getLong(details, "eventDateUTCMilliSecs"))); List<SessionResultDriverLap> lapList = new ArrayList<SessionResultDriverLap>(); JSONArray a = (JSONArray) root.get("laps"); long lastLapTime = 0; for (int i = 0; i < a.size(); i++) { JSONObject r = (JSONObject) a.get(i); SessionResultDriverLap d = new SessionResultDriverLap(); d.setLapNumber(getInt(r, "lapnum")); long lapTime = getLong(r, "time"); d.setLapTime(lapTime - lastLapTime); lastLapTime = lapTime; d.setFlags(getInt(r, "flags")); lapList.add(d); } output.setLaps(lapList); } catch (ParseException ex) { Logger.getLogger(SessionResultDriverLapsParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:cc.pinel.mangue.storage.AbstractStorage.java
/** * Finds the manga JSON object from the array * based on the manga id provided./* w ww. j a v a 2 s . c o m*/ * * @param jsonMangas the array * @param mangaId the manga id * @return the manga, if found */ protected static JSONObject findManga(JSONArray jsonMangas, String mangaId) { for (int i = 0; i < jsonMangas.size(); i++) { JSONObject jsonManga = (JSONObject) jsonMangas.get(i); Object id = jsonManga == null ? null : jsonManga.get("id"); if (id.equals(mangaId)) return jsonManga; } return null; }
From source file:com.flaptor.indextank.query.analyzers.StopAnalyzer.java
private static Set<String> getStopWords(Map<Object, Object> analyzerConfiguration) { if (analyzerConfiguration.containsKey(STOPWORDS)) { JSONArray stopwordList = (JSONArray) analyzerConfiguration.get(STOPWORDS); Set<String> stopwords = new HashSet<String>(stopwordList.size()); for (Object stopword : stopwordList) { if (!(stopword instanceof String)) { throw new IllegalArgumentException("Stopwords aren't Strings"); }/*from w w w . j av a 2 s . c om*/ stopwords.add((String) stopword); } return stopwords; } else { return ImmutableSet.of(); } }
From source file:edu.emory.library.viaf.ViafClient.java
/** * Query the VIAF AutoSuggest API to get suggestions matches for * a user-specified search term. Returns an empty list if * no matches were found or if there was an error either making * the request or parsing the response./* ww w.j a va 2 s . c o m*/ * * @param term search term * @return list of ViafResource */ public static List<ViafResource> suggest(String term) throws Exception { String uri = String.format("%s/AutoSuggest?query=%s", baseUrl, URLEncoder.encode(term, "UTF-8")); String result = EULHttpUtils.readUrlContents(uri); // todo: handle (at least log) http exceptions here List<ViafResource> resources = new ArrayList<ViafResource>(); try { // parse the JSON and initialize a list of ViafResource objects // viaf autosuggest returns in json format, with a list of results JSONObject json = (JSONObject) new JSONParser().parse(result); JSONArray jsonArray = (JSONArray) json.get("result"); for (int i = 0; i < jsonArray.size(); i++) { JSONObject obj = (JSONObject) jsonArray.get(i); // initialize a ViafResource for each result, using the viaf id and term // results may also include the following identifiers: // lc, dnb, bnf, bne, nkc, nlilat, nla ViafResource vr = new ViafResource((String) obj.get("viafid"), (String) obj.get("term")); resources.add(vr); } } catch (Exception e) { // json parsing error - should just result in any empty resource list // TODO: log the error ? } return resources; }
From source file:iracing.webapi.TrackParser.java
public static List<Track> parse(String json) { JSONParser parser = new JSONParser(); List<Track> output = null; try {//from w ww . ja v a2 s .c o m //[{"config":"Legends+Oval","priority":3,"pkgid":36,"skuname":"Atlanta+Motor+Speedway","retired":0,"price":14.95,"hasNightLighting":false,"name":"Atlanta+Motor+Speedway","lowername":"atlanta+motor+speedway","nominalLapTime":15.5574207,"lowerNameAndConfig":"atlanta+motor+speedway+legends+oval","catid":1,"priceDisplay":"14.95","id":52,"sku":10039},{"config":"Road+Course","priority":2,"pkgid":36,"skuname":"Atlanta+Motor+Speedway","retired":0,"price":14.95,"hasNightLighting":false,"name":"Atlanta+Motor+Speedway","lowername":"atlanta+motor+speedway","nominalLapTime":82.5555344,"lowerNameAndConfig":"atlanta+motor+speedway+road+course","catid":2,"priceDisplay":"14.95","id":51,"sku":10039}] JSONArray root = (JSONArray) parser.parse(json); output = new ArrayList<Track>(); for (int i = 0; i < root.size(); i++) { JSONObject o = (JSONObject) root.get(i); Track track = new Track(); track.setId(getInt(o, "id")); track.setPackageId(getInt(o, "pkgid")); track.setCategoryId(getInt(o, "catid")); track.setPriority(getInt(o, "priority")); track.setSku(getLong(o, "sku")); track.setSkuName(getString(o, "skuname", true)); track.setRetired((getInt(o, "retired")) == 1); track.setName(getString(o, "name", true)); track.setConfigName(getString(o, "config", true)); track.setHasNightLighting((Boolean) o.get("hasNightLighting")); track.setPrice(getDouble(o, "price")); track.setPriceDisplay(getString(o, "priceDisplay")); track.setNominalLapTime(getDouble(o, "nominalLapTime")); output.add(track); } } catch (ParseException ex) { Logger.getLogger(LicenseParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:Models.Taxonomy.Repository.RepositoryTNRS.java
/** * Method that consuming web services from tnrs and get results * @param name Name from specie to evaluate * @param best True for best results, false if all results * @return // w w w . ja v a 2 s . c o m */ public static TNRS[] get(String name, boolean best) { TNRS[] a = null; try { if (db == null) db = new HashMap(); if (db.containsKey(name.trim().replaceAll(" ", "_"))) return (TNRS[]) db.get(name.trim().replaceAll(" ", "_")); URL url = new URL(Configuration.getParameter("tnrs_url_base") + (best ? "retrieve=best" : "retrieve=all") + "&names=" + name.replaceAll(" ", "%20")); BufferedReader lector = new BufferedReader(new InputStreamReader(url.openStream())); String textJson = lector.readLine(); if (textJson == null) throw new Exception("Don't found item " + name); JSONArray jsNames = (JSONArray) ((JSONObject) JSONValue.parse(textJson)).get("items"); a = new TNRS[jsNames.size()]; for (int i = 0; i < a.length; i++) a[i] = new TNRS((JSONObject) jsNames.get(i)); db.put(name.trim().replaceAll(" ", "_"), a); } catch (Exception ex) { a = null; System.out.println("Error TNRS: " + ex); } return a; }
From source file:iracing.webapi.LicenseGroupParser.java
public static List<LicenseGroup> parse(String json) { JSONParser parser = new JSONParser(); List<LicenseGroup> output = null; try {//w w w. j a v a 2 s .co m JSONArray rootArray = (JSONArray) parser.parse(json); output = new ArrayList<LicenseGroup>(); for (int i = 0; i < rootArray.size(); i++) { JSONObject r = (JSONObject) rootArray.get(i); LicenseGroup lg = new LicenseGroup(); lg.setId(getInt(r, "group")); lg.setName(getString(r, "name", true)); // NOTE: the following aren't specified if not applicable Object o = r.get("minNumTT"); if (o != null) lg.setMinimumNumberOfTimeTrials(((Long) o).intValue()); o = r.get("minNumRaces"); if (o != null) lg.setMinimumNumberOfRaces(((Long) o).intValue()); output.add(lg); } } catch (ParseException ex) { Logger.getLogger(LicenseGroupParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:it.polimi.proximityapi.jsonLogic.POIJsonParser.java
public static ArrayList<POI> parsePOIFile(String jsonString) { ArrayList<POI> poiList = new ArrayList<>(); JSONParser parser = new JSONParser(); JSONArray poiArray; try {/*ww w.j a v a2 s . co m*/ poiArray = (JSONArray) parser.parse(jsonString); for (int i = 0; i < poiArray.size(); i++) { JSONObject jsonPOI = (JSONObject) poiArray.get(i); POI poi = new POI(); poi.setName((String) jsonPOI.get(JsonStrings.NAME)); poi.setLatitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LATITUDE))); poi.setLongitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LONGITUDE))); if (!jsonPOI.get(JsonStrings.RADIUS).equals("")) poi.setRadius(Float.parseFloat((String) jsonPOI.get(JsonStrings.RADIUS))); else { //Default radius set when it is not set in the corresponding JSON object poi.setRadius(TechnologyManager.BT_START_GEOFENCE_RADIUS); } poi.setBeaconUuid((String) jsonPOI.get(JsonStrings.BEACON_UUID)); poiList.add(poi); } } catch (ParseException e) { e.printStackTrace(); } return poiList; }
From source file:iracing.webapi.SeasonStandingsParser.java
public static long parse(String json, ItemHandler handler) { JSONParser parser = new JSONParser(); // System.err.println(json); long output = 0; try {// w w w . j a va 2s. c o m JSONObject root = (JSONObject) parser.parse(json); JSONObject arrayRoot = (JSONObject) root.get("d"); output = getLong(arrayRoot, "27"); JSONArray results = (JSONArray) arrayRoot.get("r"); for (int i = 0; i < results.size(); i++) { JSONObject result = (JSONObject) results.get(i); SeasonStanding standing = new SeasonStanding(); standing.setDroppedWeeks(getInt(result, "1")); standing.setClubName(getString(result, "2", true)); standing.setCountryCode(getString(result, "3", true)); standing.setLicenseSubLevel(getString(result, "4")); standing.setAverageFinish(getInt(result, "5")); standing.setIrating(getInt(result, "6")); standing.setTotalTopFives(getInt(result, "7")); standing.setMaxLicenseLevel(getInt(result, "8")); standing.setDriverName(getString(result, "9", true)); standing.setClubId(getInt(result, "10")); standing.setTotalStarts(getInt(result, "11")); standing.setDisplayCountry(getString(result, "14", true)); standing.setTotalLapsLed(getInt(result, "13")); standing.setCountry(getString(result, "15", true)); standing.setTotalWins(getInt(result, "16")); standing.setTotalIncidents(getInt(result, "17")); Object o = result.get("18"); double d; if (o instanceof Long) { Long l = (Long) o; d = l.doubleValue(); } else { d = (Double) o; } standing.setTotalPoints(d); standing.setRank(getInt(result, "20")); standing.setDivision(getInt(result, "22")); standing.setDriverCustomerId(getLong(result, "24")); standing.setWeeksCounted(getInt(result, "26")); standing.setTotalLaps(getLong(result, "28")); standing.setAverageStart(getInt(result, "29")); standing.setTotalPoles(getInt(result, "30")); standing.setPosition(getLong(result, "31")); if (!handler.onSeasonStandingParsed(standing)) break; } } catch (ParseException ex) { Logger.getLogger(SeasonStandingsParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:cloudclient.Client.java
public static void batchReceiveResp(BufferedReader in) throws IOException, ParseException { BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt")); JSONParser parser = new JSONParser(); String message;//www . j a v a 2 s .c o m while ((message = in.readLine()) != null) { //System.out.println(message); JSONArray responseList = (JSONArray) parser.parse(message); for (int i = 0; i < responseList.size(); i++) { JSONObject response = (JSONObject) responseList.get(i); bw.write(response.get("URL").toString()); bw.newLine(); } } bw.close(); }