List of usage examples for org.json JSONArray length
public int length()
From source file:com.jennifer.ui.chart.grid.DateGrid.java
private void initDomain() { if (has("target") && !has("domain")) { if (options.get("target") instanceof String) { JSONArray list = new JSONArray(); list.put(options.getString("target")); options.put("target", list); }//from w w w.j a va2s . c om JSONArray target = (JSONArray) options.getJSONArray("target"); JSONArray domain = new JSONArray(); JSONArray data = chart.data(); long min = 0; long max = 0; boolean hasMin = options.has("min"); boolean hasMax = options.has("max"); for (int i = 0, len = target.length(); i < len; i++) { String key = target.getString(i); for (int index = 0, dataLength = data.length(); index < dataLength; index++) { JSONObject row = data.getJSONObject(index); long value = 0; if (row.get(key) instanceof Date) { value = ((Date) row.get(key)).getTime(); } else { value = row.getLong(key); } if (!hasMin) { min = value; hasMin = true; } else if (min > value) min = value; if (!hasMax) { max = value; hasMax = true; } else if (max < value) max = value; } } options.put("max", max); options.put("min", min); domain.put(min).put(max); if (options.optBoolean("reverse", false)) { JSONUtil.reverse(domain); } options.put("domain", domain); } }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
@Override public void setJSONString(String jsonString) throws JSONException { clear();/* w w w .ja v a2s .c om*/ JSONObject jsonObject = new JSONObject(jsonString); Iterator<String> keySet = jsonObject.keys(); while (keySet.hasNext()) { String key = keySet.next(); String value = jsonObject.optString(key); JSONArray values = new JSONArray(value); for (int i = 0; i < values.length(); i++) add(key, values.optString(i)); } }
From source file:net.iubris.ipc_d3.cap.CamelizeSomeFieldsAndExtractInformazioniStoricheDates.java
private JSONArray adjustTimeAndTipiSpecifici(String dataAsCSV) throws ParseException { JSONArray jsonArray = CDL.toJSONArray(dataAsCSV); int length = jsonArray.length(); JSONArray jsonArrayNew = new JSONArray(); for (int i = 0; i < length; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObjectNew = new JSONObject(); jsonObjectNew.put("nome", jsonObject.getString("nome")); jsonObjectNew.put("indirizzo", jsonObject.getString("indirizzo")); jsonObjectNew.put("numeroCivico", jsonObject.getString("numero-civico")); jsonObjectNew.put("cap", jsonObject.getString("cap")); jsonObjectNew.put("quartiere", jsonObject.getString("quartiere")); jsonObjectNew.put("citta", jsonObject.getString("citta")); jsonObjectNew.put("geolocazione", jsonObject.getString("geolocazione")); jsonObjectNew.put("telefono", jsonObject.getString("telefono")); jsonObjectNew.put("mobile", jsonObject.getString("mobile")); jsonObjectNew.put("email", jsonObject.getString("email")); jsonObjectNew.put("web", jsonObject.getString("web")); jsonObjectNew.put("tipi", jsonObject.getString("tipi")); jsonObjectNew.put("tipiSpecifici", jsonObject.getString("tipi-specifici")); // jsonObjectNew.put("tipiSpecificiReduced", getTipiReduced(jsonObject)); // jsonObjectNew.put("times", getTimes(jsonObject)); LinkedList<String> date = findNumbers(jsonObject.getString("luogo-da-visitare.informazioni_storiche")); String dateString = date.toString().replace("[", "").replace("]", ""); jsonObjectNew.put("luoghiDaVisitare.informazioniStoriche.date", dateString); jsonArrayNew.put(jsonObjectNew); }//from w ww . ja v a 2 s . co m return jsonArrayNew; }
From source file:net.zorgblub.typhon.dto.PageOffsets.java
private static List<List<Integer>> readOffsets(JSONArray jsonArray) throws JSONException { List<List<Integer>> result = new ArrayList<List<Integer>>(); for (int i = 0; i < jsonArray.length(); i++) { List<Integer> sublist = new ArrayList<>(); JSONArray subArray = new JSONArray(jsonArray.getString(i)); for (int j = 0; j < subArray.length(); j++) { int val = subArray.getInt(j); sublist.add(val); }// ww w . j a v a 2 s .c o m result.add(sublist); } return result; }
From source file:mr.robotto.engine.loader.components.skeleton.MrSkeletonLoader.java
private ArrayList<String> loadBoneOrder() throws JSONException { JSONArray boneOrderJson = mRoot.getJSONArray("BoneOrder"); ArrayList<String> boneOrder = new ArrayList<>(); for (int i = 0; i < boneOrderJson.length(); i++) { String name = boneOrderJson.getString(i); boneOrder.add(name);//from ww w.j a v a2 s . c o m } return boneOrder; }
From source file:mr.robotto.engine.loader.components.skeleton.MrSkeletonLoader.java
private Map<String, MrBone> loadPose() throws JSONException { JSONArray poseJson = mRoot.getJSONArray("Pose"); Map<String, MrBone> bones = new HashMap<String, MrBone>(); for (int i = 0; i < poseJson.length(); i++) { MrBoneLoader boneLoader = new MrBoneLoader(poseJson.getJSONObject(i)); MrBone bone = boneLoader.parse(); bones.put(bone.getName(), bone); }/*from w ww.j a v a 2 s . co m*/ return bones; }
From source file:mr.robotto.engine.loader.components.skeleton.MrSkeletonLoader.java
private Map<String, MrSkeletalAction> loadActions() throws JSONException { JSONArray actionsJson = mRoot.getJSONArray("Actions"); Map<String, MrSkeletalAction> actions = new HashMap<String, MrSkeletalAction>(); for (int i = 0; i < actionsJson.length(); i++) { MrSkeletalActionLoader loader = new MrSkeletalActionLoader(actionsJson.getJSONObject(i)); MrSkeletalAction action = loader.parse(); actions.put(action.getName(), action); }// w w w.j a v a 2 s. co m return actions; }
From source file:com.android.talkback.tutorial.Tutorial.java
public Tutorial(Context context, JSONObject tutorial) throws JSONException { JSONArray lessons = JsonUtils.getJsonArray(tutorial, JSON_KEY_LESSONS); if (lessons != null && lessons.length() > 0) { int lessonCount = lessons.length(); mLessons = new TutorialLesson[lessonCount]; for (int i = 0; i < lessonCount; i++) { JSONObject lesson = lessons.getJSONObject(i); mLessons[i] = new TutorialLesson(context, lesson); }/*ww w. j a v a2 s.c o m*/ } else { mLessons = new TutorialLesson[0]; } }
From source file:com.cooperok.socialuser.fb.FbAccount.java
@Override public void checkLikePage(String pageId, final LikeCallback callback) { new Request(Session.getActiveSession(), "/me/likes/" + pageId, null, HttpMethod.GET, new Request.Callback() { public void onCompleted(Response response) { boolean result = false; GraphObject object = response.getGraphObject(); if (object != null) { JSONObject resp = object.getInnerJSONObject(); if (resp != null) { try { JSONArray data = resp.getJSONArray("data"); if (data.length() > 0) { result = true; }/* www . j av a2 s . c om*/ } catch (JSONException e) { } } } callback.onLikeChecked(result); } }).executeAsync(); }
From source file:be.brunoparmentier.openbikesharing.app.parsers.BikeNetworksListParser.java
public BikeNetworksListParser(String toParse) throws ParseException { bikeNetworks = new ArrayList<>(); try {/* ww w. ja v a2s . c om*/ JSONObject jsonObject = new JSONObject(toParse); JSONArray rawNetworks = jsonObject.getJSONArray("networks"); for (int i = 0; i < rawNetworks.length(); i++) { JSONObject rawNetwork = rawNetworks.getJSONObject(i); String id = rawNetwork.getString("id"); String name = rawNetwork.getString("name"); String company = rawNetwork.getString("company"); BikeNetworkLocation location; /* network location */ { JSONObject rawLocation = rawNetwork.getJSONObject("location"); double latitude = rawLocation.getDouble("latitude"); double longitude = rawLocation.getDouble("longitude"); String city = rawLocation.getString("city"); String country = rawLocation.getString("country"); location = new BikeNetworkLocation(latitude, longitude, city, country); } bikeNetworks.add(new BikeNetworkInfo(id, name, company, location)); } } catch (JSONException e) { throw new ParseException("Error parsing JSON", 0); } }