List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.jsonstore.api.JSONStoreChangeOptions.java
public JSONStoreChangeOptions(JSONObject js_options) throws JSONException { this();/*from w ww. ja v a2 s. c o m*/ if (js_options == null) return; if (js_options.has(ADD_NEW_KEY)) { setAddNew(js_options.getBoolean(ADD_NEW_KEY)); } if (js_options.has(MARK_DIRTY_KEY)) { setMarkDirty(js_options.getBoolean(MARK_DIRTY_KEY)); } if (js_options.has(REPLACE_CRITERIA_KEY)) { JSONArray replaceCrit = js_options.optJSONArray(REPLACE_CRITERIA_KEY); if (replaceCrit != null) { for (int i = 0; i < replaceCrit.length(); i++) { addSearchFieldToCriteria(replaceCrit.getString(i)); } } } }
From source file:me.mast3rplan.phantombot.cache.ChannelUsersCache.java
private void updateCache() throws Exception { Map<String, String> newCache = Maps.newHashMap(); JSONObject j = TwitchAPIv3.instance().GetChatUsers(channel); if (j.getBoolean("_success")) { if (j.getInt("_http") == 200) { JSONObject users = j.getJSONObject("chatters"); JSONArray mods = users.getJSONArray("moderators"); JSONArray staff = users.getJSONArray("staff"); JSONArray admins = users.getJSONArray("admins"); JSONArray global_mods = users.getJSONArray("global_mods"); JSONArray viewers = users.getJSONArray("viewers"); for (int i = 0; i < mods.length(); i++) { newCache.put(mods.getString(i), "mod"); }// w ww.java 2 s . c o m for (int i = 0; i < staff.length(); i++) { newCache.put(staff.getString(i), "staff"); } for (int i = 0; i < admins.length(); i++) { newCache.put(admins.getString(i), "admin"); } for (int i = 0; i < global_mods.length(); i++) { newCache.put(admins.getString(i), "global_mod"); } for (int i = 0; i < viewers.length(); i++) { newCache.put(viewers.getString(i), "viewer"); } } else { try { throw new Exception("[HTTPErrorException] HTTP " + j.getString("error") + ". req=" + j.getString("_type") + " " + j.getString("_url") + " " + j.getString("_post") + " " + (j.has("message") && !j.isNull("message") ? "message=" + j.getString("message") : "content=" + j.getString("_content"))); } catch (Exception e) { com.gmt2001.Console.out .println("ChannelUsersCache.updateCache>>Failed to update users: " + e.getMessage()); com.gmt2001.Console.err.logStackTrace(e); } } } else { try { throw new Exception("[" + j.getString("_exception") + "] " + j.getString("_exceptionMessage")); } catch (Exception e) { if (e.getMessage().startsWith("[SocketTimeoutException]") || e.getMessage().startsWith("[IOException]")) { Calendar c = Calendar.getInstance(); if (lastFail.after(new Date())) { numfail++; } else { numfail = 1; } c.add(Calendar.MINUTE, 1); lastFail = c.getTime(); if (numfail >= 5) { timeoutExpire = c.getTime(); } } com.gmt2001.Console.out .println("ChannelUsersCache.updateCache>>Failed to update users: " + e.getMessage()); com.gmt2001.Console.err.logStackTrace(e); } } List<String> join = Lists.newArrayList(); List<String> part = Lists.newArrayList(); for (String key : newCache.keySet()) { if (cache == null || !cache.containsKey(key)) { join.add(key); } } if (cache != null) { for (String key : cache.keySet()) { if (!newCache.containsKey(key)) { part.add(key); } } } this.cache = newCache; /* * for (String joined : join) { EventBus.instance().post(new * IrcChannelJoinEvent(PhantomBot.instance().getSession(), * PhantomBot.instance().getChannel(this.channel), joined)); } * * for (String parted : part) { EventBus.instance().post(new * IrcChannelLeaveEvent(PhantomBot.instance().getSession(), * PhantomBot.instance().getChannel(this.channel), parted, "Left")); } */ }
From source file:net.straylightlabs.archivo.net.MindCommandIdSearch.java
/** * Build a URL for downloading the video file associated with this recording. *///from w ww .j av a2 s. com public URL getDownloadUrl() { failOnInvalidState(); try { if (response.has(OBJECT_ID)) { JSONArray ids = response.getJSONArray(OBJECT_ID); String id = ids.getString(0).replaceFirst("mfs:rc\\.", ""); String title = URLEncoder.encode(recording.getSeriesTitle(), RPC_ENCODING); String tsFormat = "&Format=video/x-tivo-mpeg-ts"; if (compatibilityMode) { tsFormat = ""; } String url = String.format("http://%s/download/%s.TiVo?Container=%%2FNowPlaying&id=%s%s", tivo.getClient().getAddress().getHostAddress(), title, id, tsFormat); return new URL(url); } } catch (UnsupportedEncodingException | MalformedURLException e) { logger.error("Error building download URL: ", e); } throw new IllegalStateException("No URL for recording"); }
From source file:com.dubsar_dictionary.Dubsar.model.Autocompleter.java
@Override public void parseData(Object jsonResponse) throws JSONException { /*// www.ja v a 2 s.c om * Expect data like [ "term", [ "result1", "result2", ... "result10" ] ] * (based on the OpenSearch protocol) */ JSONArray response = (JSONArray) jsonResponse; JSONArray list = response.getJSONArray(1); mResults = new ArrayList<String>(list.length()); for (int j = 0; j < list.length(); ++j) { mResults.add(list.getString(j)); } }
From source file:m2.android.archetype.example.FacebookSdk.internal.Utility.java
static Map<String, Object> convertJSONObjectToHashMap(JSONObject jsonObject) { HashMap<String, Object> map = new HashMap<String, Object>(); JSONArray keys = jsonObject.names(); for (int i = 0; i < keys.length(); ++i) { String key;/*w ww . j a va2 s .c om*/ try { key = keys.getString(i); Object value = jsonObject.get(key); if (value instanceof JSONObject) { value = convertJSONObjectToHashMap((JSONObject) value); } map.put(key, value); } catch (JSONException e) { } } return map; }
From source file:com.dubsar_dictionary.Dubsar.model.Search.java
@Override public void parseData(Object jsonResponse) throws JSONException { JSONArray response = (JSONArray) jsonResponse; JSONArray list = response.getJSONArray(1); mTotalPages = response.getInt(2);// w w w. ja v a2 s. c o m mResults = new ArrayList<Word>(list.length()); for (int j = 0; j < list.length(); ++j) { JSONArray entry = list.getJSONArray(j); int _id = entry.getInt(0); String name = entry.getString(1); String posString = entry.getString(2); int freqCnt = entry.getInt(3); String otherForms = entry.getString(4); Word word = new Word(_id, name, posString); word.setFreqCnt(freqCnt); word.setInflections(otherForms); mResults.add(word); } }
From source file:com.panchosoft.appspy.models.iTunesProxy.java
public iTunesApp[] buscarApp(String appName, int limit) { // Hacemos una bsqueda en iTunes String datos_json = buscarDatosAppJSON(appName, 15); if (datos_json == null || datos_json.length() == 0) { return null; }/*from w w w. j a va2s . co m*/ try { JSONObject ob = new JSONObject(datos_json); if (ob == null) { return null; } int totalResultados = ob.getInt("resultCount"); if (totalResultados == 0) { return null; } iTunesApp[] appsencontradas = new iTunesApp[totalResultados]; for (int c = 0; c < totalResultados; c++) { JSONArray resultados = ob.getJSONArray("results"); if (resultados == null) { return null; } JSONObject appdata = resultados.getJSONObject(c); if (appdata == null) { return null; } // Creamos el objeto iTunesApp iTunesApp app = new iTunesApp(); app.setArtistId(appdata.opt("artistId").toString()); app.setArtistName(appdata.optString("artistName")); app.setArtistViewUrl(appdata.optString("artistViewUrl")); app.setArtworkUrl100(appdata.optString("artworkUrl100")); app.setArtworkUrl60(appdata.optString("artworkUrl60")); app.setContentAdvisoryRating(appdata.optString("advisorRating")); app.setDescription(appdata.optString("description")); app.setFileSizeBytes(appdata.optString("fileSizeBytes")); // Generos JSONArray generos = appdata.getJSONArray("genreIds"); String[] generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenreIds(generosApp); // Generos nombres generos = appdata.getJSONArray("genres"); generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenres(generosApp); // Lenguajes JSONArray lenguajes = appdata.getJSONArray("genres"); String[] lenguajesApp = new String[lenguajes.length()]; for (int i = 0; i < lenguajes.length(); i++) { lenguajesApp[i] = lenguajes.getString(i); } app.setLanguageCodesISO2(lenguajesApp); app.setPrice(appdata.optString("price")); app.setPrimaryGenreId(appdata.optString("primaryGenreId")); app.setPrimaryGenreName(appdata.optString("primaryGenreName")); app.setReleaseDate(appdata.optString("releaseDate")); // Capturas JSONArray capturas = appdata.getJSONArray("screenshotUrls"); String[] capturasApp = new String[capturas.length()]; for (int i = 0; i < capturas.length(); i++) { capturasApp[i] = capturas.getString(i); } app.setScreenshotUrls(capturasApp); app.setSellerName(appdata.optString("sellerName")); app.setSellerUrl(appdata.optString("sellerUrl")); // Dispositivos soportados JSONArray dispositivos = appdata.getJSONArray("supportedDevices"); String[] dispositivosApp = new String[dispositivos.length()]; for (int i = 0; i < dispositivos.length(); i++) { dispositivosApp[i] = dispositivos.getString(i); } app.setSupportedDevices(dispositivosApp); app.setTrackCensoredName(appdata.optString("trackCensoredName")); app.setTrackName(appdata.optString("trackName")); app.setTrackViewUrl(appdata.optString("trackViewUrl")); app.setVersion(appdata.optString("version")); appsencontradas[c] = app; } return appsencontradas; } catch (JSONException ex) { Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage()); } return null; }
From source file:com.panchosoft.appspy.models.iTunesProxy.java
public iTunesApp obtenerAppPorID(String appID) { // Hacemos una bsqueda en iTunes String datos_json = obtenerDatosAppJSON(appID); if (datos_json == null || datos_json.length() == 0) { return null; }//from w ww .ja v a 2s . com try { JSONObject ob = new JSONObject(datos_json); if (ob == null) { return null; } JSONArray resultados = ob.getJSONArray("results"); if (resultados == null) { return null; } JSONObject appdata = resultados.getJSONObject(0); if (appdata == null) { return null; } // Creamos el objeto iTunesApp iTunesApp app = new iTunesApp(); app.setArtistId(appdata.opt("artistId").toString()); app.setArtistName(appdata.optString("artistName")); app.setArtistViewUrl(appdata.optString("artistViewUrl")); app.setArtworkUrl100(appdata.optString("artworkUrl100")); app.setArtworkUrl60(appdata.optString("artworkUrl60")); app.setContentAdvisoryRating(appdata.optString("advisorRating")); app.setDescription(appdata.optString("description")); app.setFileSizeBytes(appdata.optString("fileSizeBytes")); // Generos JSONArray generos = appdata.getJSONArray("genreIds"); String[] generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenreIds(generosApp); // Generos nombres generos = appdata.getJSONArray("genres"); generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenres(generosApp); // Lenguajes JSONArray lenguajes = appdata.getJSONArray("genres"); String[] lenguajesApp = new String[lenguajes.length()]; for (int i = 0; i < lenguajes.length(); i++) { lenguajesApp[i] = lenguajes.getString(i); } app.setLanguageCodesISO2(lenguajesApp); app.setPrice(appdata.optString("price")); app.setPrimaryGenreId(appdata.optString("primaryGenreId")); app.setPrimaryGenreName(appdata.optString("primaryGenreName")); app.setReleaseDate(appdata.optString("releaseDate")); // Capturas JSONArray capturas = appdata.getJSONArray("screenshotUrls"); String[] capturasApp = new String[capturas.length()]; for (int i = 0; i < capturas.length(); i++) { capturasApp[i] = capturas.getString(i); } app.setScreenshotUrls(capturasApp); app.setSellerName(appdata.optString("sellerName")); app.setSellerUrl(appdata.optString("sellerUrl")); // Dispositivos soportados JSONArray dispositivos = appdata.getJSONArray("supportedDevices"); String[] dispositivosApp = new String[dispositivos.length()]; for (int i = 0; i < dispositivos.length(); i++) { dispositivosApp[i] = dispositivos.getString(i); } app.setSupportedDevices(dispositivosApp); app.setTrackCensoredName(appdata.optString("trackCensoredName")); app.setTrackName(appdata.optString("trackName")); app.setTrackViewUrl(appdata.optString("trackViewUrl")); app.setVersion(appdata.optString("version")); return app; } catch (JSONException ex) { Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage()); } return null; }
From source file:com.panchosoft.appspy.models.iTunesProxy.java
public iTunesApp obtenerApp(String appName) { // Hacemos una bsqueda en iTunes String datos_json = buscarDatosAppJSON(appName, 1); if (datos_json == null || datos_json.length() == 0) { return null; }/*from ww w . j a v a 2 s. c o m*/ try { JSONObject ob = new JSONObject(datos_json); if (ob == null) { return null; } JSONArray resultados = ob.getJSONArray("results"); if (resultados == null) { return null; } JSONObject appdata = resultados.getJSONObject(0); if (appdata == null) { return null; } // Creamos el objeto iTunesApp iTunesApp app = new iTunesApp(); app.setArtistId(appdata.opt("artistId").toString()); app.setArtistName(appdata.optString("artistName")); app.setArtistViewUrl(appdata.optString("artistViewUrl")); app.setArtworkUrl100(appdata.optString("artworkUrl100")); app.setArtworkUrl60(appdata.optString("artworkUrl60")); app.setContentAdvisoryRating(appdata.optString("advisorRating")); app.setDescription(appdata.optString("description")); app.setFileSizeBytes(appdata.optString("fileSizeBytes")); // Generos JSONArray generos = appdata.getJSONArray("genreIds"); String[] generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenreIds(generosApp); // Generos nombres generos = appdata.getJSONArray("genres"); generosApp = new String[generos.length()]; for (int i = 0; i < generos.length(); i++) { generosApp[i] = generos.getString(i); } app.setGenres(generosApp); // Lenguajes JSONArray lenguajes = appdata.getJSONArray("genres"); String[] lenguajesApp = new String[lenguajes.length()]; for (int i = 0; i < lenguajes.length(); i++) { lenguajesApp[i] = lenguajes.getString(i); } app.setLanguageCodesISO2(lenguajesApp); app.setPrice(appdata.optString("price")); app.setPrimaryGenreId(appdata.optString("primaryGenreId")); app.setPrimaryGenreName(appdata.optString("primaryGenreName")); app.setReleaseDate(appdata.optString("releaseDate")); // Capturas JSONArray capturas = appdata.getJSONArray("screenshotUrls"); String[] capturasApp = new String[capturas.length()]; for (int i = 0; i < capturas.length(); i++) { capturasApp[i] = capturas.getString(i); } app.setScreenshotUrls(capturasApp); app.setSellerName(appdata.optString("sellerName")); app.setSellerUrl(appdata.optString("sellerUrl")); // Dispositivos soportados JSONArray dispositivos = appdata.getJSONArray("supportedDevices"); String[] dispositivosApp = new String[dispositivos.length()]; for (int i = 0; i < dispositivos.length(); i++) { dispositivosApp[i] = dispositivos.getString(i); } app.setSupportedDevices(dispositivosApp); app.setTrackCensoredName(appdata.optString("trackCensoredName")); app.setTrackName(appdata.optString("trackName")); app.setTrackViewUrl(appdata.optString("trackViewUrl")); app.setVersion(appdata.optString("version")); return app; } catch (JSONException ex) { Logger.getLogger("com.panchosoft.itunes").log(Level.WARNING, "Error: " + ex.getMessage()); } return null; }
From source file:com.tonikorin.cordova.plugin.LocationProvider.LocationProviderPlugin.java
/** * Executes the request.//from w w w . j a v a 2 s. co m * * @param action The action to execute. * @param args The exec() arguments. * @param callback The callback context used when calling back into * JavaScript. * @return Returning false results in a "MethodNotFound" error. * @throws JSONException */ @Override public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException { if (action.equalsIgnoreCase("setConfiguration")) { JSONObject config = args.getJSONObject(0); saveConfiguration(config); return true; } else if (action.equalsIgnoreCase("getAndClearHistory")) { JSONObject history = readAndClearHistory(); callback.success(history); return true; } else if (action.equalsIgnoreCase("startService")) { String notification = args.getString(0); startService(notification); // for testing your config without GCM return true; } return false; }