public JSONArray optJSONArray(int index) { return jsonArray.optJSONArray(index); }
JSONArray arr = new JSONArray(jsonStr);//Response string is here for (int i = 0; i < arr.length(); i++) { JSONArray arr2 = arr.optJSONArray(i); for (int j = 0; j < arr2.length(); j++) { jObject = arr2.getJSONObject(0); } }
JSONArray jarray = new JSONArray(jsonStr); for (int i = 0; i < jarray.length(); i++) { JSONArray innerArray = jarray.optJSONArray(i); for (int j = 0; j < innerArray.length(); j++) { jObject = innerArray.getJSONObject(j); } }
public void setPositions(JSONArray positions) { this.mPositions.clear(); if (positions != null) { for (int i = 0; i < positions.length(); i++) { JSONArray position = positions.optJSONArray(i); if (position != null) { this.mPositions.add(new Position(position)); } } } }
public void setLineStrings(JSONArray lineStrings) { this.mLineStrings.clear(); if (lineStrings != null) { for (int i = 0; i < lineStrings.length(); i++) { JSONArray lineJSON = lineStrings.optJSONArray(i); if (lineJSON != null) { this.mLineStrings.add(new LineString(lineJSON)); } } } }
JSONObject jb=Util.parseJson(query); JSONArray ja=jb.optJSONArray("picture") JSONArray v=ja.optJSONArray("data") JSONObject j=v.optJSONObject(0); j.get("name").toString(); j.get("url").toString();
public void setRings(JSONArray rings) { this.mRings.clear(); if (rings != null) { for (int i = 0; i < rings.length(); i++) { JSONArray ringJSON = rings.optJSONArray(i); if (ringJSON != null) { this.mRings.add(new Ring(ringJSON)); } } } }
JSONArray jsonArray=new JSONArray(data); if(jsonArray!=null && jsonArray.length()>0){ for (int i = 0; i < jsonArray.length(); i++) { JSONArray childJsonArray=jsonArray.optJSONArray(i); if(childJsonArray!=null && childJsonArray.length()>0){ for (int j = 0; j < childJsonArray.length(); j++) { System.out.println(childJsonArray.optString(j)); } } } }
public void setPolygons(JSONArray polygons) { this.mPolygons.clear(); if (polygons != null) { for (int i = 0; i < polygons.length(); i++) { JSONArray polyJSON = polygons.optJSONArray(i); if (polyJSON != null) { this.mPolygons.add(new Polygon(polyJSON)); } } } }
for(int i=0;i<jArray.length();i++) { JSONObject jsonObject = new JSONObject(jArray.getString(i)); JSONArray workinfo = jsonObject.optJSONArray("additional_info"); if (workinfo != null) { for(int j=0;j<workinfo.length();j++) { JSONArray values = workinfo.optJSONArray(j); for(int z=0;z<values.length();z++) { Log.i("MyActivity", "got work obj as " + values.optString(z)); } } } }
JSONArray jsonArray=response.getJSONArray("results"); if(jsonArray!=null && jsonArray.length()>0){ for (int i = 0; i < jsonArray.length(); i++) { JSONArray childJsonArray=jsonArray.optJSONArray(i); if(childJsonArray!=null && childJsonArray.length()>0){ for (int j = 0; j < childJsonArray.length(); j++) { System.out.println(childJsonArray.optString(j)); } } } }
private class TweetJsonListener implements Listener<JSONArray> { @Override public void onResponse(JSONArray response) { JSONObject jsonObject = null; JSONArray tweets = response.optJSONArray("statuses"); int count = tweets != null ? tweets.length() : 0; for (int i = 0; i < count; i++) { jsonObject = tweets.optJSONObject(i); if (jsonObject != null) { tweetAdapter.add(jsonObject); } activity.setProgressBarIndeterminateVisibility(false); } }
JSONArray result = new JSONArray(res); if (result.length() > 0){ for (int i = 0; i < result.length(); ++i) { JSONObject menuObject = result.optJSONObject(i); if(menuObject == null) { JSONArray arr = result.optJSONArray(i); // process the array } else { // process the object } }
/** * @param funcJSON * @return the function result can only be either a Double or a JSONArray; * @throws JSONException */ private Object getValueFromFunction(JSONObject funcJSON) throws JSONException { String function = funcJSON.optString(QueryConstructor.FUNCTION_NAME); if (function.length() == 0) throw new IllegalArgumentException( "No function name is defined in ExpressionQuery's function json: " + funcJSON); JSONArray params = funcJSON.optJSONArray(QueryConstructor.PARAMS_PARAM); if (params == null) throw new IllegalArgumentException( "No function param is defined in ExpressionQuery's function json: " + funcJSON); if (function.equals("length")) { // get the first and only the first parameter for length function; JSONArray param = params.optJSONArray(0); if (param == null) throw new IllegalArgumentException("No param is provided for function '" + function + "' defined in ExpressionQuery's function json: " + funcJSON); return (double) param.length(); } else throw new IllegalArgumentException("Unsupported function '" + function + "' in ExpressionQuery's function json: " + funcJSON); }
public JSONObject filterKeywordMetadata(JSONObject inputMetadata) throws JSONException { if ( _startBucket != null && _endBucket != null ) { if ( _startBucket > _endBucket ) { throw new IllegalArgumentException("Filter by keyword bucket transformer arguments are invalid. start time bucket: " + _startBucket + ", end time bucket: " + _endBucket); } } JSONObject map = inputMetadata.getJSONObject("map"); JSONArray bins = map.getJSONArray("bins"); JSONArray filteredBins = new JSONArray(); int binSize = bins.length(); int start = ( _startBucket != null ) ? _startBucket : 0; int end = ( _endBucket != null ) ? _endBucket : (binSize-1); for ( int i=0; i<binSize; i++ ) { if ( i >= start && i <= end ) { filteredBins.put(i, bins.optJSONArray(i)); } else { filteredBins.put(i, (JSONArray)null); } } map.put("bins", filteredBins); return inputMetadata; }
@Nullable public <IT> AsonArray<IT> getJsonArray(int index) { if (index < 0 || index > array.length() - 1) { throw new IndexOutOfBoundsException("Index " + index + " is out of bounds for this array!"); } JSONArray ary = array.optJSONArray(index); if (isNull(ary)) { return null; } return new AsonArray<>(ary); }
private void doSpell(final String cmd, final String id, final JSONArray paramArray) { final SpellChecker checker = new SpellChecker(dict); final Set<String> errors = new HashSet<String>(); checker.addSpellCheckListener(new SpellCheckListener() { public void spellingError(SpellCheckEvent event) { errors.add(event.getInvalidWord()); } }); JSONArray words = paramArray.optJSONArray(1); checker.checkSpelling(new StringWordTokenizer(words.toString())); respond(errors.iterator(), cmd, id); }
private void doSpell(final String cmd, final String id, final JSONArray paramArray) { final SpellChecker checker = new SpellChecker(dict); final Set<String> errors = new HashSet<String>(); checker.addSpellCheckListener(new SpellCheckListener() { public void spellingError(SpellCheckEvent event) { errors.add(event.getInvalidWord()); } }); JSONArray words = paramArray.optJSONArray(1); checker.checkSpelling(new StringWordTokenizer(words.toString())); respond(errors.iterator(), cmd, id); }
private BitfinexSubmittedOrder jsonToBitfinexSubmittedOrder(JSONArray array) { final JSONArray orderJson = array.optJSONArray(4); final long oid = orderJson.optLong(0, -1); final int gid = orderJson.optInt(1, -1); final long cid = orderJson.optLong(2, -1); final String symbol = orderJson.optString(3); final String stateValue = array.optString(7); final String state = array.optString(6); final BitfinexSubmittedOrder submittedOrder = new BitfinexSubmittedOrder(); if (oid != -1) { submittedOrder.setOrderId(oid); } if (gid != -1) { submittedOrder.setClientGroupId(gid); } if( cid != -1) { submittedOrder.setClientId(cid); } if (!Strings.isNullOrEmpty(symbol)) { submittedOrder.setCurrencyPair(BitfinexCurrencyPair.fromSymbolString(symbol)); } submittedOrder.setStatus(BitfinexSubmittedOrderStatus.ERROR); logger.error("State for order {} is {}, reason is {}", submittedOrder.getOrderId(), state, stateValue); return submittedOrder; }
/** * Assert that two {@link JSONArray JSONArrays} are equal, comparing index by index recursively. * * @param first the first array * @param second the second array */ public static void assertJsonArrayEquals(JSONArray first, JSONArray second) { if (assertSameNullity(first, second)) { return; } assertEquals(first.length(), second.length()); for (int i = 0; i < first.length(); i++) { if (first.opt(i) instanceof JSONObject) { assertTrue(second.opt(i) instanceof JSONObject); assertJsonEquals(first.optJSONObject(i), second.optJSONObject(i)); } else if (first.opt(i) instanceof JSONArray) { assertTrue(second.opt(i) instanceof JSONArray); assertJsonArrayEquals(first.optJSONArray(i), second.optJSONArray(i)); } else if (first.opt(i) instanceof Number) { assertTrue(second.opt(i) instanceof Number); assertEquals(((Number) first.opt(i)).longValue(), ((Number) second.opt(i)).longValue()); } else { assertEquals(first.opt(i), second.opt(i)); } } }