List of usage examples for org.json JSONArray JSONArray
public JSONArray(Object array) throws JSONException
From source file:net.bither.api.GetExchangeTrendApi.java
@Override public void setResult(String response) throws Exception { JSONArray jsonArray = new JSONArray(response); this.result = TrendingGraphicData.format(jsonArray); }
From source file:com.olmectron.material.utils.MultipartUtility.java
public JSONArray sendPostJSONRequest() { try {/* w ww.java 2s .co m*/ String respuesta = sendPostRequest(); //JSONObject jObject = new JSONObject(respuesta); JSONArray jArray; if (!respuesta.startsWith("[")) { respuesta = "[]"; } jArray = new JSONArray(respuesta); return jArray; } catch (JSONException ex) { Logger.getLogger(MultipartUtility.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.droidparts.persist.sql.EntityManager.java
protected Object readFromCursor(Cursor cursor, int columnIndex, Class<?> valType, Class<?> arrCollItemType) throws IllegalArgumentException { if (cursor.isNull(columnIndex)) { return null; } else if (isBoolean(valType)) { return cursor.getInt(columnIndex) == 1; } else if (isByte(valType)) { return Byte.valueOf(cursor.getString(columnIndex)); } else if (isByteArray(valType)) { return cursor.getBlob(columnIndex); } else if (isDouble(valType)) { return cursor.getDouble(columnIndex); } else if (isFloat(valType)) { return cursor.getFloat(columnIndex); } else if (isInteger(valType)) { return cursor.getInt(columnIndex); } else if (isLong(valType)) { return cursor.getLong(columnIndex); } else if (isShort(valType)) { return cursor.getShort(columnIndex); } else if (isString(valType)) { return cursor.getString(columnIndex); } else if (isUUID(valType)) { return UUID.fromString(cursor.getString(columnIndex)); } else if (isDate(valType)) { return new Date(cursor.getLong(columnIndex)); } else if (isBitmap(valType)) { byte[] arr = cursor.getBlob(columnIndex); return BitmapFactory.decodeByteArray(arr, 0, arr.length); } else if (isJsonObject(valType) || isJsonArray(valType)) { String str = cursor.getString(columnIndex); try {/*from w w w . jav a2 s. c om*/ return isJsonObject(valType) ? new JSONObject(str) : new JSONArray(str); } catch (JSONException e) { throw new IllegalArgumentException(e); } } else if (isEnum(valType)) { return instantiateEnum(valType, cursor.getString(columnIndex)); } else if (isEntity(valType)) { long id = cursor.getLong(columnIndex); @SuppressWarnings("unchecked") Entity entity = instantiate((Class<Entity>) valType); entity.id = id; return entity; } else if (isArray(valType) || isCollection(valType)) { String str = cursor.getString(columnIndex); String[] parts = (str.length() > 0) ? str.split("\\" + SEP) : new String[0]; if (isArray(valType)) { return toTypeArr(arrCollItemType, parts); } else { @SuppressWarnings("unchecked") Collection<Object> coll = (Collection<Object>) instantiate(valType); coll.addAll(toTypeColl(arrCollItemType, parts)); return coll; } } else { throw new IllegalArgumentException("Need to manually read " + valType.getName() + " from cursor."); } }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<Player> getNearbyPlayers(Location location, String ticketHash) throws JSONException, ParseException, IOException, AuthenticationException { if (location == null) return null; try {//ww w .j a v a 2 s. co m URI playersQuery = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + location.getLatitude() + "/" + location.getLongitude(), null, null); JSONArray players = new JSONArray(doSimpleGet(playersQuery, ticketHash)); return Player.fromJSONArray(players); } catch (URISyntaxException e) { return null; //TDOD inform caller that their query is bad } }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<Player> searchForPlayers(String query, String ticketHash) throws JSONException, ParseException, IOException, AuthenticationException { try {// w ww. j av a 2s.c om URI playersQuery = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players", PARAM_PLAYER_NAME + "=" + query, null); JSONArray players = new JSONArray(doSimpleGet(playersQuery, ticketHash)); return Player.fromJSONArray(players); } catch (URISyntaxException e) { return null; //TDOD inform caller that their query is bad } }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<LibraryEntry> availableMusicQuery(String query, String playerId, String authToken) throws JSONException, ParseException, IOException, AuthenticationException, PlayerInactiveException, NoLongerInPlayerException, KickedException { try {/* www. j a v a 2 s .c o m*/ URI uri = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + playerId + "/available_music", "query=" + query, null); JSONArray libEntries = new JSONArray(doPlayerRelatedGet(uri, authToken)); return LibraryEntry.fromJSONArray(libEntries); } catch (URISyntaxException e) { //TODO inform caller that their query is bad } return null; }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<String> getArtists(String playerId, String authToken) throws JSONException, ParseException, IOException, AuthenticationException, PlayerInactiveException, NoLongerInPlayerException, KickedException { try {/*from w w w .j a v a2 s . c o m*/ URI uri = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + playerId + "/available_music/artists", null, null); JSONArray artists = new JSONArray(doPlayerRelatedGet(uri, authToken)); return toStringList(artists); } catch (URISyntaxException e) { //TODO inform caller that their query is bad } return null; }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<LibraryEntry> getSongsByArtists(String artistQuery, String playerId, String authToken) throws JSONException, ParseException, IOException, AuthenticationException, PlayerInactiveException, NoLongerInPlayerException, KickedException { try {/*from www. java 2 s.co m*/ URI uri = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + playerId + "/available_music/artists/" + artistQuery, null, null); JSONArray libEntries = new JSONArray(doPlayerRelatedGet(uri, authToken)); return LibraryEntry.fromJSONArray(libEntries); } catch (URISyntaxException e) { //TODO inform caller that their query is bad } return null; }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<LibraryEntry> getRandomMusic(int max, String playerId, String authToken) throws JSONException, ParseException, IOException, AuthenticationException, PlayerInactiveException, NoLongerInPlayerException, KickedException { try {//from w w w . j ava 2s . c om URI uri = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + playerId + "/available_music/random_songs", "max_randoms=" + String.valueOf(max), null); JSONArray libEntries = new JSONArray(doPlayerRelatedGet(uri, authToken)); return LibraryEntry.fromJSONArray(libEntries); } catch (URISyntaxException e) { //TODO inform caller that their query is bad } return null; }
From source file:org.klnusbaum.udj.network.ServerConnection.java
public static List<LibraryEntry> getRecentlyPlayedLibEntries(int max, String playerId, String authToken) throws JSONException, ParseException, IOException, AuthenticationException, PlayerInactiveException, NoLongerInPlayerException, KickedException { try {// w w w . j a v a 2 s .c o m URI uri = new URI(NETWORK_PROTOCOL, null, SERVER_HOST, SERVER_PORT, "/udj/0_6/players/" + playerId + "/recently_played", "max_songs=" + String.valueOf(max), null); JSONArray recentlyPlayedEntries = new JSONArray(doPlayerRelatedGet(uri, authToken)); return LibraryEntry.fromRecentlyPlayedJSONArray(recentlyPlayedEntries); } catch (URISyntaxException e) { //TODO inform caller that their query is bad } return null; }