ArrayList<String> list = new ArrayList<String>(); JSONArray jsonArray = (JSONArray)jsonObject; if (jsonArray != null) { int len = jsonArray.length(); for (int i=0;i<len;i++){ list.add(jsonArray.get(i).toString()); } }
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; } }
ArrayList<String> list = new ArrayList<String>(); JSONArray jsonArray = (JSONArray)jsonObject; int len = jsonArray.length(); if (jsonArray != null) { for (int i=0;i<len;i++){ list.add(jsonArray.get(i).toString()); } } //Remove the element from arraylist list.remove(position); //Recreate JSON Array JSONArray jsArray = new JSONArray(list);
private List<String> getPostsFromSinglePage(JSONObject json) { List<String> imageURLs = new ArrayList<>(); JSONArray datas; if (json.getJSONObject("entry_data").getJSONArray("PostPage") .getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media") .has("edge_sidecar_to_children")) { datas = json.getJSONObject("entry_data").getJSONArray("PostPage") .getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media") .getJSONObject("edge_sidecar_to_children").getJSONArray("edges"); for (int i = 0; i < datas.length(); i++) { JSONObject data = (JSONObject) datas.get(i); data = data.getJSONObject("node"); if (data.has("is_video") && data.getBoolean("is_video")) { imageURLs.add(data.getString("video_url")); } else { imageURLs.add(data.getString("display_url")); } } } else { JSONObject data = json.getJSONObject("entry_data").getJSONArray("PostPage") .getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media"); if (data.getBoolean("is_video")) { imageURLs.add(data.getString("video_url")); } else { imageURLs.add(data.getString("display_url")); } } return imageURLs; }
private static void _upgradeClozeModel(Collection col, JSONObject m) throws ConfirmModSchemaException { try { m.put("type", Consts.MODEL_CLOZE); // convert first template JSONObject t = m.getJSONArray("tmpls").getJSONObject(0); for (String type : new String[] { "qfmt", "afmt" }) { t.put(type, t.getString(type).replaceAll("\\{\\{cloze:1:(.+?)\\}\\}", "{{cloze:$1}}")); } t.put("name", "Cloze"); // delete non-cloze cards for the model JSONArray ja = m.getJSONArray("tmpls"); ArrayList<JSONObject> rem = new ArrayList<>(); for (int i = 1; i < ja.length(); i++) { JSONObject ta = ja.getJSONObject(i); if (!ta.getString("afmt").contains("{{cloze:")) { rem.add(ta); } } for (JSONObject r : rem) { col.getModels().remTemplate(m, r); } JSONArray newArray = new JSONArray(); newArray.put(ja.get(0)); m.put("tmpls", newArray); col.getModels()._updateTemplOrds(m); col.getModels().save(m); } catch (JSONException e) { throw new RuntimeException(e); } }
List<Object> objectList = new ArrayList<Object>(); for (int i = 0; i < array.length(); ++i) { if (arrayClass.isEnum()) { objectList.add(getEnumValue(array.getString(i), arrayClass)); } else if (canDirectlySerializeClass(arrayClass)) { objectList.add(array.get(i)); } else { JSONObject jsonObject = array.getJSONObject(i);
public void moveTemplate(JSONObject m, JSONObject template, int idx) { try { JSONArray ja = m.getJSONArray("tmpls"); int oldidx = -1; ArrayList<JSONObject> l = new ArrayList<>(); HashMap<Integer, Integer> oldidxs = new HashMap<>(); for (int i = 0; i < ja.length(); ++i) { if (ja.get(i).equals(template)) { oldidx = i; if (idx == oldidx) { m.put("tmpls", new JSONArray(l)); _updateTemplOrds(m); ja = m.getJSONArray("tmpls"); for (int i = 0; i < ja.length(); ++i) { JSONObject t = ja.getJSONObject(i); sb.append("when ord = ").append(oldidxs.get(t.hashCode())).append(" then ").append(t.getInt("ord")); if (i != ja.length() - 1) { sb.append(" ");
JSONObject json = new JSONObject(jsonString); String valueType = json.getString(JSON_VALUE_TYPE); JSONArray jsonArray = json.getJSONArray(JSON_VALUE); boolean[] array = new boolean[jsonArray.length()]; for (int i = 0; i < array.length; i++) { array[i] = jsonArray.getBoolean(i); String charString = json.getString(JSON_VALUE); if (charString != null && charString.length() == 1) { bundle.putChar(key, charString.charAt(0)); bundle.putString(key, json.getString(JSON_VALUE)); } else if (valueType.equals(TYPE_STRING_LIST)) { JSONArray jsonArray = json.getJSONArray(JSON_VALUE); int numStrings = jsonArray.length(); ArrayList<String> stringList = new ArrayList<String>(numStrings); for (int i = 0; i < numStrings; i++) { Object jsonStringValue = jsonArray.get(i); stringList.add( i,
private static JSONArray filterInnerClasses(JSONArray json, List<String> classes) { JSONArray retJson = new JSONArray(); for (int i = 0; i < json.length() ; i++) { JSONObject classDetails = (JSONObject) json.get(i); if (classes.contains(classDetails.getString("class"))) { retJson.put(classDetails); } } return retJson; }
mOptions = mCol.getDecks().confForDid(mDeck.getLong("id")); mValues.put("name", mDeck.getString("name")); mValues.put("desc", mDeck.getString("desc")); mValues.put("deckConf", mDeck.getString("conf")); mValues.put("maxAnswerTime", mOptions.getString("maxTaken")); mValues.put("newSteps", StepsPreference.convertFromJSON(newOptions.getJSONArray("delays"))); mValues.put("newGradIvl", newOptions.getJSONArray("ints").getString(0)); mValues.put("newEasy", newOptions.getJSONArray("ints").getString(1)); mValues.put("newFactor", Integer.toString(newOptions.getInt("initialFactor") / 10)); mValues.put("newOrder", newOptions.getString("order")); mValues.put("reminderTime", String.format("%1$02d:%2$02d", reminderTime.get(0), reminderTime.get(1))); } else { mValues.put("reminderEnabled", "false");
for(int i=0; i<jsonArray.length(); i++) { JSONObject obj = new JSONObject(jsonArray.get(i).toString()); String reqLoc = ""; boolean check = true; for(int j=0; j<obj.getString("location").length(); j++) { if(obj.getString("location").charAt(j)==' ') { check = false; reqLoc += obj.getString("location").charAt(j);
/** * Converts the provided {@link JSONArray} to a Map of {@link JSONObject}s where the key of each object * is the value at {@code uniqueKey} in each object. * * @param array the JSON array to convert * @param uniqueKey the key to map the JSON objects to * @return the map of {@link JSONObject}s from {@code array} * @throws JSONException JSON parsing error */ public static Map<Object, JSONObject> arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException { Map<Object, JSONObject> valueMap = new HashMap<Object, JSONObject>(); for (int i = 0; i < array.length(); ++i) { JSONObject jsonObject = (JSONObject) array.get(i); Object id = jsonObject.get(uniqueKey); valueMap.put(id, jsonObject); } return valueMap; }
public void remField(JSONObject m, JSONObject field) throws ConfirmModSchemaException { mCol.modSchema(true); try { JSONArray ja = m.getJSONArray("flds"); JSONArray ja2 = new JSONArray(); int idx = -1; for (int i = 0; i < ja.length(); ++i) { if (field.equals(ja.getJSONObject(i))) { idx = i; continue; } ja2.put(ja.get(i)); } m.put("flds", ja2); int sortf = m.getInt("sortf"); if (sortf >= m.getJSONArray("flds").length()) { m.put("sortf", sortf - 1); } _updateFieldOrds(m); _transformFields(m, new TransformFieldDelete(idx)); if (idx == sortIdx(m)) { // need to rebuild mCol.updateFieldCache(Utils.toPrimitive(nids(m))); } renameField(m, field, null); } catch (JSONException e) { throw new RuntimeException(e); } }
assert (m.getJSONArray("tmpls").length() > 1); JSONArray ja = m.getJSONArray("tmpls"); int ord = -1; for (int i = 0; i < ja.length(); ++i) { if (ja.get(i).equals(template)) { ord = i; break; "update cards set ord = ord - 1, usn = ?, mod = ? where nid in (select id from notes where mid = ?) and ord > ?", new Object[] { mCol.usn(), Utils.intNow(), m.getLong("id"), ord }); JSONArray tmpls = m.getJSONArray("tmpls"); JSONArray ja2 = new JSONArray(); for (int i = 0; i < tmpls.length(); ++i) { if (template.equals(tmpls.getJSONObject(i))) { continue; ja2.put(tmpls.get(i));
break; case "newGradIvl": { JSONArray ja = new JSONArray(); // [graduating, easy] ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(1)); mOptions.getJSONObject("new").put("ints", ja); break; JSONArray ja = new JSONArray(); // [graduating, easy] ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(0)); ja.put(value); mOptions.getJSONObject("new").put("ints", ja); reminder.put("time", mOptions.getJSONObject("reminder").getJSONArray("time")); } else { reminder.put("time", new JSONArray() .put(TimePreference.parseHours(TimePreference.DEFAULT_VALUE)) .put(TimePreference.parseMinutes(TimePreference.DEFAULT_VALUE)));
String longitude = obj.getJSONObject("locations").getJSONObject(place).getJSONArray("location").get(0) .toString(); String lattitude = obj.getJSONObject("locations").getJSONObject(place).getJSONArray("location").get(1) .toString(); JSONArray jsonArray = new JSONArray(); jsonArray.put(wikiGeoResult);
public static String computeMessageId(JSONObject message, SourceType sourceType) throws Exception { JSONArray location = message.getJSONArray("location_point"); if (location == null) { throw new Exception("location_point not found"); } String longitude, latitude; try { Object rawLon = location.get(1); longitude = rawLon instanceof Integer ? Integer.toString((Integer) rawLon) : (rawLon instanceof Double ? Double.toString((Double) rawLon) : (String) rawLon); Object rawLat = location.get(0); latitude = rawLat instanceof Integer ? Integer.toString((Integer) rawLat) : (rawLat instanceof Double ? Double.toString((Double) rawLat) : (String) rawLat); } catch (ClassCastException e) { throw new ClassCastException("Unable to extract lat, lon from location_point " + e.getMessage()); } // Modification time = 'mtime' value. If not found, take current time Object mtime = message.get("mtime"); if (mtime == null) { mtime = Long.toString(System.currentTimeMillis()); message.put("mtime", mtime); } // Id format : <source_type>_<lat>_<lon>_<mtime> return sourceType.toString() + "_" + latitude + "_" + longitude + "_" + mtime; }
/** * Displays news informations on the console from Github web service. * Infos concern the general roadmap for the application, current development status * and other useful statements for the community. */ public static void showNews() { try { JSONArray news = GitUtil.getJSONObject().getJSONArray("news"); for (int index = 0 ; index < news.length() ; index++) { LOGGER.info(news.get(index)); } } catch (IOException e) { LOGGER.warn("Connection to the Github News Webservice failed", e); } }