List of usage examples for org.json.simple JSONArray size
public int size()
From source file:mp3downloader.ZingSearch.java
private static ArrayList<Song> readSongsFromContent(String content) throws ParseException { ArrayList<Song> songs = new ArrayList<Song>(); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(content); JSONArray items = (JSONArray) obj.get("Data"); for (int i = 0; i < items.size(); i++) { JSONObject item = (JSONObject) items.get(i); String id = (String) item.get("ID"); String title = (String) item.get("Title"); String performer = (String) item.get("Artist"); String thumbnail = (String) item.get("ArtistAvatar"); String source = ""; if (item.get("LinkDownload320") != null) { source = (String) item.get("LinkDownload320"); } else if (item.get("LinkDownload128") != null) { source = (String) item.get("LinkDownload128"); }//from w w w. j a v a2 s . com String type = "mp3"; Song song = new Song(id, title, performer, source, thumbnail, type); songs.add(song); } return songs; }
From source file:mp3downloader.ZingSearch.java
public static ArrayList<Playlist> searchPlaylist(String term) { ArrayList<Playlist> playlists = new ArrayList<>(); try {//from www.j av a 2 s . c om String content = getSearchResult(term, 8); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(content); JSONArray items = (JSONArray) obj.get("Data"); for (int i = 0; i < items.size(); i++) { JSONObject item = (JSONObject) items.get(i); String id = (String) item.get("ID"); String title = (String) item.get("Title"); String artist = (String) item.get("Artist"); String genre = (String) item.get("Genre"); String pictureUrl = (String) item.get("PictureURL"); long totalListen = 0; if (item.get("TotalListen") != null) { totalListen = (long) item.get("TotalListen"); } Playlist p = new Playlist(id, title, artist, genre, pictureUrl, totalListen); playlists.add(p); } } catch (Exception ex) { Logger.getLogger(ZingSearch.class.getName()).log(Level.SEVERE, null, ex); } return playlists; }
From source file:com.rmtheis.yandtran.YandexTranslatorAPI.java
private static String[] jsonArrToStringArr(final String inputString, final String propertyName) throws Exception { final JSONArray jsonArr = (JSONArray) JSONValue.parse(inputString); String[] values = new String[jsonArr.size()]; int i = 0;// www .j a v a2 s . c om for (Object obj : jsonArr) { if (propertyName != null && propertyName.length() != 0) { final JSONObject json = (JSONObject) obj; if (json.containsKey(propertyName)) { values[i] = json.get(propertyName).toString(); } } else { values[i] = obj.toString(); } i++; } return values; }
From source file:com.serena.rlc.provider.jenkins.domain.JobParameter.java
public static List<JobParameter> parse(String options) { List<JobParameter> list = new ArrayList<>(); JSONParser parser = new JSONParser(); try {/*ww w. j ava 2 s .co m*/ Object parsedObject = parser.parse(options); JSONArray array = (JSONArray) ((JSONObject) parsedObject).get("actions"); for (Object action : array) { JSONArray paramDefs = (JSONArray) ((JSONObject) action).get("parameterDefinitions"); if (paramDefs != null && paramDefs.size() > 0) { for (Object param : paramDefs) { JobParameter obj = new JobParameter(); JSONObject jsonObject = (JSONObject) param; obj.setName((String) jsonObject.get("name")); obj.setType((String) jsonObject.get("type")); try { JSONObject deafultValueJsonObject = (JSONObject) jsonObject .get("defaultParameterValue"); obj.setDefaultValue((String) deafultValueJsonObject.get("value")); } catch (Exception ex) { } list.add(obj); } } } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return list; }
From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java
public static Map<String, UUID> call(List<String> names) { names = new ArrayList<String>(names); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String playerName = iterator.next(); if (fetchedUUIDs.containsKey(playerName)) { iterator.remove();//from w ww . jav a 2 s.co m } } if (names.size() == 0) { return readonlyFetchedUUIDs; } int count = names.size(); DebugLogger.info("get UUIDs for " + names.size() + " player(s)"); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); try { for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); count -= array.size(); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); fetchedUUIDs.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (count > 0) { MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost."); } return readonlyFetchedUUIDs; }
From source file:iracing.webapi.SeasonParser.java
public static List<Season> parse(String json) { JSONParser parser = new JSONParser(); List<Season> output = null; try {/*from ww w . jav a 2 s.c o m*/ JSONArray rootArray = (JSONArray) parser.parse(json); output = new ArrayList<Season>(); for (int i = 0; i < rootArray.size(); i++) { JSONObject r = (JSONObject) rootArray.get(i); Season season = new Season(); season.setId(getInt(r, "seasonid")); season.setPrefImage(getString(r, "prefimg", true)); season.setSeriesName(getString(r, "seriesname", true)); season.setSeasonShortName(getString(r, "seasonshortname", true)); season.setWhatsHotImage(getString(r, "whatshotimg", true)); season.setCautionTypeRoad(getInt(r, "cautionTypeRoad")); season.setCautionTypeOval(getInt(r, "cautionTypeOval")); season.setRaceWeeks(getInt(r, "raceweek")); season.setActive((Boolean) r.get("active")); season.setMinimumSafetyRating(getString(r, "minsr")); season.setMinimumLicenseLevel(getInt(r, "minlicenselevel")); season.setMaximumLicenseLevel(getInt(r, "maxlicenselevel")); JSONArray array = (JSONArray) r.get("tracks"); List<Season.Track> trackList = new ArrayList<Season.Track>(); // to work around a website bug where tracks are listed 3 times each, // we only add ones that have different raceweek values int lastRaceWeek = -1; for (int j = 0; j < array.size(); j++) { //{"config":"","priority":0,"raceweek":0,"pkgid":90,"night":0,"name":"Mosport+International+Raceway","id":144,"lowername":"mosport+international+raceway"} JSONObject o = (JSONObject) array.get(j); int raceWeek = getInt(o, "raceweek"); if (raceWeek != lastRaceWeek) { Season.Track track = new Season.Track(); track.setId(getInt(o, "id")); track.setNightMode((getInt(o, "night")) == 1); trackList.add(track); lastRaceWeek = raceWeek; } } season.setTracks(trackList); //"carclasses":[{"carsinclass":[{"name":"Cadillac+CTS-V+Racecar","id":41}],"shortname":"Cadillac+CTS-VR","name":"Cadillac+CTS-VR","id":45,"lowername":"cadillac+cts-vr"}] List<Integer> carClasses = new ArrayList<Integer>(); array = (JSONArray) r.get("carclasses"); for (int j = 0; j < array.size(); j++) { JSONObject o = (JSONObject) array.get(j); //JSONArray array2 = (JSONArray)o.get("carsinclass"); carClasses.add(getInt(o, "id")); } season.setCarClasses(carClasses); season.setApiUserClubAllowed((Boolean) r.get("isClubAllowed")); season.setSeriesLicenseGroupId(getInt(r, "serieslicgroupid")); season.setCurrentTrack(getInt(r, "currentTrack")); season.setSeriesId(getInt(r, "seriesid")); season.setLicenseGroupId(getInt(r, "licgroupid")); season.setLicenseIgnoredForPractice((Boolean) r.get("ignoreLicenseForPractice")); season.setWorldCupEvent((Boolean) r.get("isWorldCup")); season.setStartDate(new Date(getLong(r, "start"))); season.setEndDate(new Date(getLong(r, "end"))); array = (JSONArray) r.get("cars"); List<Integer> carList = new ArrayList<Integer>(); for (int j = 0; j < array.size(); j++) { JSONObject o = (JSONObject) array.get(j); carList.add(getInt(o, "id")); } season.setCars(carList); season.setMultiClass((Boolean) r.get("multiclass")); season.setRegionalCompetitionEvent((Boolean) r.get("isRegionCompetition")); season.setQuarter(getInt(r, "quarter")); season.setYear(getInt(r, "year")); season.setSeriesShortName(getString(r, "seriesshortname", true)); season.setCategoryId(getInt(r, "catid")); // also stored under 'category' season.setOfficial((Boolean) r.get("isOfficial")); season.setApiUserLicenseEligible((Boolean) r.get("licenseEligible")); season.setComplete((Boolean) r.get("complete")); output.add(season); } } catch (ParseException ex) { Logger.getLogger(SeasonParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:MyTest.ParseJson.java
private static void getDetailInfo(JSONObject jstep_detail) { // System.out.println(jstep_detail); long id = (long) jstep_detail.get("id"); System.out.println("id:" + id); String name = (String) jstep_detail.get("name"); System.out.println("name:" + name); JSONArray inputs = (JSONArray) jstep_detail.get("inputs"); if (inputs.isEmpty()) { System.out.println("inputs:null"); } else {//from w w w . j ava 2 s . c om System.out.println("inputs:"); for (int i = 0; i < inputs.size(); i++) { System.out.println(inputs.get(i) + "\n"); } } JSONArray outpus = (JSONArray) jstep_detail.get("outputs"); if (outpus.isEmpty()) { System.out.println("outpus:null"); } else { System.out.println("outpus:"); for (int i = 0; i < outpus.size(); i++) { System.out.print(outpus.get(i) + "\n"); } } JSONObject links = (JSONObject) jstep_detail.get("input_connections"); if (links.isEmpty()) { System.out.println("input_connections:null"); } else { Iterator it = links.keySet().iterator(); System.out.println("input_connections: "); while (it.hasNext()) { Object input_link = it.next(); System.out.println(links.get(input_link)); } } System.out.println("-------------------------------------------------------"); }
From source file:com.github.itoshige.testrail.util.ConfigrationUtil.java
private static List<RunIdInfo> getRunIdInfos(JSONArray runIds) { List<RunIdInfo> runIdInfos = new ArrayList<RunIdInfo>(); for (int i = 0; i < runIds.size(); i++) { JSONObject runIdInfo = (JSONObject) runIds.get(i); runIdInfos.add(new RunIdInfo(runIdInfo.get("target"), runIdInfo.get("runId"))); }/*from w w w . ja va 2 s . c o m*/ Collections.sort(runIdInfos, new RunIdInfoComparator()); return runIdInfos; }
From source file:iracing.webapi.HostedSessionResultSummaryParser.java
static long parse(String json, ItemHandler handler) { JSONParser parser = new JSONParser(); // System.err.println(json); long output = 0; if (!"{}".equals(json)) { try {/*from www .j a v a2 s .co m*/ JSONObject root = (JSONObject) parser.parse(json); output = getLong(root, "rowcount"); JSONArray rootArray = (JSONArray) root.get("rows"); for (int i = 0; i < rootArray.size(); i++) { JSONObject r = (JSONObject) rootArray.get(i); HostedSessionResultSummary summary = new HostedSessionResultSummary(); summary.setWasPrivate((getInt(r, "private")) == 1); summary.setDriverSearchedBestLapTime(getLong(r, "bestlaptime")); summary.setDriverSearchedStartingPosition(getInt(r, "startingposition")); summary.setDriverSearchedClassStartingPosition(getInt(r, "classstartingposition")); summary.setDriverSearchedFinishingPosition(getInt(r, "finishingposition")); summary.setDriverSearchedClassFinishingPosition(getInt(r, "classfinishingposition")); summary.setDriverSearchedCarClassId(getInt(r, "carclassid")); summary.setDriverSearchedIncidents(getInt(r, "incidents")); summary.setPracticeLength(getInt(r, "practicelength")); summary.setQualifyingLaps(getInt(r, "qualifylaps")); summary.setQualifyingLength(getInt(r, "qualifylength")); summary.setRaceLaps(getInt(r, "racelaps")); summary.setRaceLength(getInt(r, "racelength")); summary.setStartTime(new Date(getLong(r, "start_time"))); summary.setMinimumLicenseLevel(getInt(r, "minliclevel")); summary.setMaximumLicenseLevel(getInt(r, "maxliclevel")); summary.setMinimumIrating(getInt(r, "minir")); summary.setMaximumIrating(getInt(r, "maxir")); summary.setPrivateSessionId(getLong(r, "privatesessionid")); IracingCustomer host = new IracingCustomer(); host.setId(getLong(r, "host_custid")); host.setName(getString(r, "host_displayname", true)); summary.setHost(host); summary.setHostLicenseLevel(getInt(r, "host_licenselevel")); summary.setSessionName(getString(r, "sessionname", true)); summary.setTrackId(getInt(r, "trackid")); summary.setTrackName(getString(r, "track_name", true)); IracingCustomer winner = new IracingCustomer(); winner.setId(getLong(r, "winner_custid")); winner.setName(getString(r, "winner_displayname", true)); summary.setWinner(winner); summary.setWinnerLicenseLevel(getInt(r, "winner_licenselevel")); summary.setSessionId(getLong(r, "sessionid")); summary.setSubSessionId(getLong(r, "subsessionid")); summary.setSubSessionFinishedAt(new Date(getLong(r, "subsessionfinishedat"))); summary.setRaceFinishedAt(new Date(getLong(r, "racefinishedat"))); summary.setLoneQualifying((getInt(r, "lonequalify")) == 1); summary.setHardcoreLevelId(getInt(r, "hardcorelevel")); summary.setNightMode((getInt(r, "nightmode")) == 1); summary.setRestarts(getInt(r, "restarts")); summary.setFullCourseCautions((getInt(r, "fullcoursecautions")) == 1); summary.setRollingStarts((getInt(r, "rollingstarts")) == 1); summary.setMultiClass((getInt(r, "multiclass")) == 1); summary.setFixedSetup((getInt(r, "fixed_setup")) == 1); summary.setNumberOfFastTows(getInt(r, "numfasttows")); String s = getString(r, "carids", true); String[] sa = s.split(","); List<Integer> carIds = new ArrayList<Integer>(); for (String carId : sa) { carIds.add(Integer.parseInt(carId)); } summary.setCars(carIds); s = getString(r, "max_pct_fuel_fills", true); if (!"".equals(s)) { sa = s.split(","); List<Integer> maxFuelFills = new ArrayList<Integer>(); for (String mff : sa) { maxFuelFills.add(Integer.parseInt(mff)); } summary.setMaximumPercentageFuelFills(maxFuelFills); } summary.setMaximumDrivers(getInt(r, "maxdrivers")); summary.setCreated(new Date(getLong(r, "created"))); summary.setSessionFastestLap(getLong(r, "sessionfastlap")); summary.setCategoryId(getInt(r, "catid")); handler.onHostedSessionResultSummaryParsed(summary); } } catch (ParseException ex) { Logger.getLogger(HostedSessionResultSummaryParser.class.getName()).log(Level.SEVERE, null, ex); } } return output; }
From source file:kjscompiler.Program.java
private static void run() throws ParseException, IOException, NullPointerException { Settings settings = new Settings(settingsPath); System.out.println("Searching for " + settings.getPattern() + " in " + settings.getBaseDir()); JSONArray Base = settings.getBaseDir(); List<String> files = new ArrayList<String>(); for (int i = 0; i < Base.size(); i++) { files.addAll(FileScanner.run((String) Base.get(i), settings.getPattern(), settings.getProjectPath())); }/*from w ww . j a v a 2 s .com*/ System.out.println("Found " + files.size() + " files"); List<FileInfo> fiPrimaries = new ArrayList<FileInfo>(); List<String> pExternals = new ArrayList<String>(); Hashtable<String, Integer> fiHtPrimaries = new Hashtable<String, Integer>(); for (String fullpath : files) { FileInfo fi = new FileInfo(fullpath); if (!fi.getIsIgnore()) { if (fi.getIsExternal()) { pExternals.add(fi.getFilename()); } else { fiPrimaries.add(fi); } } } System.out.println("Primaries: " + fiPrimaries.size() + " files"); System.out.println("Externals: " + pExternals.size() + " files"); OrderDeps od = new OrderDeps(fiPrimaries); List<FileInfo> ordered = od.getOrderedFiles(); List<String> oErrors = od.getErrors(); for (int i = 0, length = oErrors.size(); i < length; i++) { String err = oErrors.get(i); System.out.println("Order Error #" + (i + 1) + ": " + err); } System.out.println("Primaries ordered"); List<String> pPrimaries = new ArrayList<String>(); for (int i = 0, length = ordered.size(); i < length; i++) { pPrimaries.add(ordered.get(i).getFilename()); } String compilationLevel = settings.getLevel(); GoogleClosureCompiler compiler = new GoogleClosureCompiler(pPrimaries, settings.getOutput(), compilationLevel, pExternals); compiler.setWrapper(settings.getWrapper()); compiler.setWarningLevel(WarningLevel.VERBOSE); compiler.run(); System.out.println("Compiled file: " + settings.getOutput()); JSError[] errors = compiler.getErrors(); for (int i = 0, length = errors.length; i < length; i++) { JSError err = errors[i]; System.out.println("Error #" + (i + 1) + ": " + err.description + " in " + err.sourceName + " (" + err.lineNumber + ")"); } if (errors.length == 0) { JSError[] warnings = compiler.getWarnings(); for (int i = 0, length = warnings.length; i < length; i++) { JSError warn = errors[i]; System.out.println("Warning #" + (i + 1) + ": " + warn.description + " in " + warn.sourceName + " (" + warn.lineNumber + ")"); } } System.out.println("\n\n Thank you for using kJScompiler!\n Who said JavaScript can't be compiled?\n"); System.exit(0); }