Refine search
JSONArray jsonArray = new JSONArray(sJSON); JSONArray jsonPersonData = jsonArray.getJSONArray(1); for (int i=0; i<jsonPersonData.length(); i++) { JSONObject item = jsonPersonData.getJSONObject(i); String name = item.getString("name"); String surname = item.getString("surname"); }
private Object deepObjectFromJson(int deep, int current, JSONArray array) { if (deep <= current) { return null; } if (array.length() > 0) { if (deep == current + 1 && !(array.get(0) instanceof JSONArray)) { return array.get(0); } if (array.get(0) instanceof JSONArray) { return deepObjectFromJson(deep, ++current, array.getJSONArray(0)); } } return null; } }
/** * Parses an array containing coordinates into an ArrayList of LatLng objects * * @param coordinates array containing the GeoJSON coordinates * @return ArrayList of LatLng objects * @throws JSONException if coordinates cannot be parsed */ private static ArrayList<LatLngAlt> parseCoordinatesArray(JSONArray coordinates) throws JSONException { ArrayList<LatLngAlt> coordinatesArray = new ArrayList<>(); for (int i = 0; i < coordinates.length(); i++) { coordinatesArray.add(parseCoordinate(coordinates.getJSONArray(i))); } return coordinatesArray; }
/** * Creates a new GeoJsonMultiPoint object containing an array of GeoJsonPoint objects * * @param coordinates array containing the coordinates for the GeoJsonMultiPoint * @return GeoJsonMultiPoint object * @throws JSONException if coordinates cannot be parsed */ private static GeoJsonMultiPoint createMultiPoint(JSONArray coordinates) throws JSONException { ArrayList<GeoJsonPoint> geoJsonPoints = new ArrayList<GeoJsonPoint>(); for (int i = 0; i < coordinates.length(); i++) { geoJsonPoints.add(createPoint(coordinates.getJSONArray(i))); } return new GeoJsonMultiPoint(geoJsonPoints); }
/** * Parses an array of arrays containing coordinates into an ArrayList of an ArrayList of LatLng * objects * * @param coordinates array of an array containing the GeoJSON coordinates * @return ArrayList of an ArrayList of LatLng objects * @throws JSONException if coordinates cannot be parsed */ private static ArrayList<ArrayList<LatLng>> parseCoordinatesArrays(JSONArray coordinates) throws JSONException { ArrayList<ArrayList<LatLng>> coordinatesArray = new ArrayList<>(); for (int i = 0; i < coordinates.length(); i++) { ArrayList<LatLngAlt> latLngAlts = parseCoordinatesArray(coordinates.getJSONArray(i)); //this method is called for polygons, which do not have altitude values ArrayList<LatLng> latLngs = new ArrayList<>(); for (LatLngAlt latLngAlt : latLngAlts) { latLngs.add(latLngAlt.latLng); } coordinatesArray.add(latLngs); } return coordinatesArray; }
/** * Creates a new GeoJsonMultiPolygon object containing an array of GeoJsonPolygon objects * * @param coordinates array containing the coordinates for the GeoJsonMultiPolygon * @return GeoJsonPolygon object * @throws JSONException if coordinates cannot be parsed */ private static GeoJsonMultiPolygon createMultiPolygon(JSONArray coordinates) throws JSONException { ArrayList<GeoJsonPolygon> geoJsonPolygons = new ArrayList<>(); for (int i = 0; i < coordinates.length(); i++) { geoJsonPolygons.add(createPolygon(coordinates.getJSONArray(i))); } return new GeoJsonMultiPolygon(geoJsonPolygons); }
/** * Creates a new GeoJsonMultiLineString object containing an array of GeoJsonLineString objects * * @param coordinates array containing the coordinates for the GeoJsonMultiLineString * @return GeoJsonMultiLineString object * @throws JSONException if coordinates cannot be parsed */ private static GeoJsonMultiLineString createMultiLineString(JSONArray coordinates) throws JSONException { ArrayList<GeoJsonLineString> geoJsonLineStrings = new ArrayList<>(); for (int i = 0; i < coordinates.length(); i++) { geoJsonLineStrings.add(createLineString(coordinates.getJSONArray(i))); } return new GeoJsonMultiLineString(geoJsonLineStrings); }
/** * Cards/notes/revlog ******************************************************************** */ private void mergeRevlog(JSONArray logs) { for (int i = 0; i < logs.length(); i++) { try { mCol.getDb().execute("INSERT OR IGNORE INTO revlog VALUES (?,?,?,?,?,?,?,?,?)", Utils.jsonArray2Objects(logs.getJSONArray(i))); } catch (SQLException | JSONException e) { throw new RuntimeException(e); } } }
JSONArray arr = new JSONArray(props.getProperty("extra-keys", "[['ESC', 'TAB', 'CTRL', 'ALT', '-', 'DOWN', 'UP']]")); mExtraKeys = new String[arr.length()][]; for (int i = 0; i < arr.length(); i++) { JSONArray line = arr.getJSONArray(i); mExtraKeys[i] = new String[line.length()]; for (int j = 0; j < line.length(); j++) { mExtraKeys[i][j] = line.getString(j);
private void mergeDecks(JSONArray rchg) { try { JSONArray decks = rchg.getJSONArray(0); for (int i = 0; i < decks.length(); i++) { JSONObject r = decks.getJSONObject(i); JSONObject l = mCol.getDecks().get(r.getLong("id"), false); // if missing locally or server is newer, update if (l == null || r.getLong("mod") > l.getLong("mod")) { mCol.getDecks().update(r); } } JSONArray confs = rchg.getJSONArray(1); for (int i = 0; i < confs.length(); i++) { JSONObject r = confs.getJSONObject(i); JSONObject l = mCol.getDecks().getConf(r.getLong("id")); // if missing locally or server is newer, update if (l == null || r.getLong("mod") > l.getLong("mod")) { mCol.getDecks().updateConf(r); } } } catch (JSONException e) { throw new RuntimeException(e); } }
for (int i = 0; i < reqArray.length(); i++) { JSONArray sr = reqArray.getJSONArray(i); JSONArray req = sr.getJSONArray(2); for (int j = 0; j < req.length(); j++) { int idx = req.getInt(j); if (fields[idx] == null || fields[idx].length() == 0) { for (int j = 0; j < req.length(); j++) { int idx = req.getInt(j); if (fields[idx] != null && fields[idx].length() != 0) {
if (entry.getKey().equals("search")) { JSONArray ar = mDeck.getJSONArray("terms"); ar.getJSONArray(0).put(0, entry.getValue()); mDeck.put("terms", ar); } else if (entry.getKey().equals("limit")) { JSONArray ar = mDeck.getJSONArray("terms"); ar.getJSONArray(0).put(1, entry.getValue()); mDeck.put("terms", ar); } else if (entry.getKey().equals("order")) { JSONArray ar = mDeck.getJSONArray("terms"); ar.getJSONArray(0).put(2, Integer.parseInt((String) entry.getValue())); mDeck.put("terms", ar); } else if (entry.getKey().equals("resched")) { if (on) { JSONArray steps = StepsPreference.convertToJSON(mValues.get("steps")); if (steps.length() > 0) { mDeck.put("delays", steps); JSONObject presetValues = new JSONObject(dynExamples[i]); JSONArray ar = presetValues.names(); for (int j = 0; j < ar.length(); j++) { String name = ar.getString(j); if (name.equals("steps")) {
private ArrayList<Object[]> newerRows(JSONArray data, String table, int modIdx) { long[] ids = new long[data.length()]; try { for (int i = 0; i < data.length(); i++) { ids[i] = data.getJSONArray(i).getLong(0); for (int i = 0; i < data.length(); i++) { JSONArray r = data.getJSONArray(i); if (!lmods.containsKey(r.getLong(0)) || lmods.get(r.getLong(0)) < r.getLong(modIdx)) { update.add(Utils.jsonArray2Objects(r));
JSONObject json = new JSONObject(jsonStrings[jsonStrings.length - 1]); JSONArray videos = json.getJSONArray("all"); LOGGER.info("Found " + videos.length() + " videos"); for (int i = 0; i < videos.length(); i++) { JSONArray jsonVideo = videos.getJSONArray(i); int vidid = jsonVideo.getInt(1); String videoURL = com.rarchives.ripme.ripper.rippers.video.VkRipper.getVideoURLAtPage(
private void assertResultSet(SpannerImpl.GrpcResultSet actual, JSONArray expected) throws Exception { int i = 0; while (actual.next()) { Struct actualRow = actual.getCurrentRowAsStruct(); JSONArray expectedRow = expected.getJSONArray(i); assertRow(actualRow, expectedRow); i++; } assertThat(i).isEqualTo(expected.length()); }
if (delays.length() > 0) { dyn.put("delays", delays); } else { ar.getJSONArray(0).put(0, "deck:\"" + deckName + "\" " + terms[0]); ar.getJSONArray(0).put(1, terms[1]); ar.getJSONArray(0).put(2, terms[2]); dyn.put("resched", resched);
private void assertArray(List<?> actualValues, JSONArray expectedList) throws Exception { assertThat(actualValues.size()).isEqualTo(expectedList.length()); for (int i = 0; i < actualValues.size(); i++) { Object actualValue = actualValues.get(i); if (actualValue == null) { assertThat(expectedList.isNull(i)).isTrue(); } else { if (actualValue instanceof Boolean) { assertThat((Boolean) actualValue).isEqualTo(expectedList.getBoolean(i)); } else if (actualValue instanceof String) { assertThat((String) actualValue).isEqualTo(expectedList.getString(i)); } else if (actualValue instanceof Long) { assertThat((Long) actualValue).isEqualTo(expectedList.getLong(i)); } else if (actualValue instanceof Double) { assertThat((Double) actualValue).isEqualTo(expectedList.getDouble(i)); } else if (actualValue instanceof ByteArray) { assertThat((ByteArray) actualValue) .isEqualTo(ByteArray.fromBase64(expectedList.getString(i))); } else if (actualValue instanceof Struct) { Struct actualStruct = (Struct) actualValue; JSONArray expectedFields = expectedList.getJSONArray(i); assertRow(actualStruct, expectedFields); } } } } }
mCol.log("mediaChanges resp count: ", data.length()); if (data.length() == 0) { break; lastUsn = data.getJSONArray(data.length()-1).getInt(1); for (int i = 0; i < data.length(); i++) { throw new RuntimeException("UserAbortedSync"); String fname = data.getJSONArray(i).getString(0); int rusn = data.getJSONArray(i).getInt(1); String rsum = null; if (!data.getJSONArray(i).isNull(2)) { rsum = data.getJSONArray(i).optString(2);
private void assertRow(Struct actualRow, JSONArray expectedRow) throws Exception { assertThat(actualRow.getColumnCount()).isEqualTo(expectedRow.length()); for (int i = 0; i < expectedRow.length(); i++) { switch (actualRow.getColumnType(i).getCode()) { case BOOL: assertThat(actualRow.getBoolean(i)).isEqualTo(expectedRow.getBoolean(i)); break; case STRING: assertThat(actualRow.getString(i)).isEqualTo(expectedRow.getString(i)); break; case INT64: assertThat(actualRow.getLong(i)).isEqualTo(expectedRow.getLong(i)); break; case FLOAT64: assertThat(actualRow.getDouble(i)).isEqualTo(expectedRow.getDouble(i)); break; case BYTES: assertThat(actualRow.getBytes(i)) .isEqualTo(ByteArray.fromBase64(expectedRow.getString(i))); break; case ARRAY: Type elementType = actualRow.getColumnType(i).getArrayElementType(); assertArray(getRawList(actualRow, i, elementType), expectedRow.getJSONArray(i)); break; default: Assert.fail("Unexpected type code:" + actualRow.getColumnType(i).getCode()); } } }
try { JSONArray array = jsonObject.getJSONArray("coordinates"); for (int i = 0; i < array.length(); ++i) { JSONArray point = array.getJSONArray(i); coordinates.add(new ParseGeoPoint(point.getDouble(0), point.getDouble(1)));