List of usage examples for org.json JSONObject getJSONArray
public JSONArray getJSONArray(String key) throws JSONException
From source file:com.github.sommeri.sourcemap.SourceMapConsumerV3.java
/** * Parses the given contents containing a source map. *//*from w w w .j a v a2s . c o m*/ public void parse(JSONObject sourceMapRoot, SourceMapSupplier sectionSupplier) throws SourceMapParseException { try { // Check basic assertions about the format. int version = sourceMapRoot.getInt("version"); if (version != 3) { throw new SourceMapParseException("Unknown version: " + version); } this.file = sourceMapRoot.getString("file"); if (file.isEmpty()) { //SMS: (source map separation): commented this - I need more tolerant parser //throw new SourceMapParseException("File entry is missing or empty "); } if (sourceMapRoot.has("sourceRoot")) this.sourceRoot = sourceMapRoot.getString("sourceRoot"); if (sourceMapRoot.has("sections")) { // Looks like a index map, try to parse it that way. parseMetaMap(sourceMapRoot, sectionSupplier); return; } lineCount = sourceMapRoot.getInt("lineCount"); String lineMap = sourceMapRoot.getString("mappings"); sources = getJavaStringArray(sourceMapRoot.getJSONArray("sources")); if (sourceMapRoot.has("sourcesContent")) { sourcesContent = getJavaStringArray(sourceMapRoot.getJSONArray("sourcesContent")); } else { sourcesContent = new String[sources.length]; } names = getJavaStringArray(sourceMapRoot.getJSONArray("names")); lines = new ArrayList<ArrayList<Entry>>(lineCount); new MappingBuilder(lineMap).build(); } catch (JSONException ex) { throw new SourceMapParseException("JSON parse exception: " + ex); } }
From source file:com.github.sommeri.sourcemap.SourceMapConsumerV3.java
/** * @param sourceMapRoot/* w w w . j a va2 s . co m*/ * @throws SourceMapParseException */ private void parseMetaMap(JSONObject sourceMapRoot, SourceMapSupplier sectionSupplier) throws SourceMapParseException { if (sectionSupplier == null) { sectionSupplier = new DefaultSourceMapSupplier(); } try { // Check basic assertions about the format. int version = sourceMapRoot.getInt("version"); if (version != 3) { throw new SourceMapParseException("Unknown version: " + version); } String file = sourceMapRoot.getString("file"); if (file.isEmpty()) { throw new SourceMapParseException("File entry is missing or empty"); } if (sourceMapRoot.has("lineCount") || sourceMapRoot.has("mappings") || sourceMapRoot.has("sources") || sourceMapRoot.has("names")) { throw new SourceMapParseException("Invalid map format"); } SourceMapGeneratorV3 generator = new SourceMapGeneratorV3(); JSONArray sections = sourceMapRoot.getJSONArray("sections"); for (int i = 0, count = sections.length(); i < count; i++) { JSONObject section = sections.getJSONObject(i); if (section.has("map") && section.has("url")) { throw new SourceMapParseException( "Invalid map format: section may not have both 'map' and 'url'"); } JSONObject offset = section.getJSONObject("offset"); int line = offset.getInt("line"); int column = offset.getInt("column"); String mapSectionContents; if (section.has("url")) { String url = section.getString("url"); mapSectionContents = sectionSupplier.getSourceMap(url); if (mapSectionContents == null) { throw new SourceMapParseException("Unable to retrieve: " + url); } } else if (section.has("map")) { mapSectionContents = section.getString("map"); } else { throw new SourceMapParseException( "Invalid map format: section must have either 'map' or 'url'"); } generator.mergeMapSection(line, column, mapSectionContents); } StringBuilder sb = new StringBuilder(); try { generator.appendTo(sb, file); } catch (IOException e) { // Can't happen. throw new RuntimeException(e); } parse(sb.toString()); } catch (IOException ex) { throw new SourceMapParseException("IO exception: " + ex); } catch (JSONException ex) { throw new SourceMapParseException("JSON parse exception: " + ex); } }
From source file:com.foxykeep.datadroidpoc.data.factory.PersonListJsonFactory.java
public static ArrayList<Person> parseResult(String wsResponse) throws DataException { ArrayList<Person> personList = new ArrayList<Person>(); try {//from w w w. ja va 2 s. co m JSONObject parser = new JSONObject(wsResponse); JSONObject jsonRoot = parser.getJSONObject(JSONTag.PERSON_LIST_ELEM_PERSONS); JSONArray jsonPersonArray = jsonRoot.getJSONArray(JSONTag.PERSON_LIST_ELEM_PERSON); int size = jsonPersonArray.length(); for (int i = 0; i < size; i++) { JSONObject jsonPerson = jsonPersonArray.getJSONObject(i); Person person = new Person(); person.firstName = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_FIRST_NAME); person.lastName = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_LAST_NAME); person.email = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_EMAIL); person.city = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_CITY); person.postalCode = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_POSTAL_CODE); person.age = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_AGE); person.isWorking = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_IS_WORKING) == 1; personList.add(person); } } catch (JSONException e) { Log.e(TAG, "JSONException", e); throw new DataException(e); } return personList; }
From source file:com.norman0406.slimgress.API.Knobs.PortalKnobs.java
public PortalKnobs(JSONObject json) throws JSONException { super(json);// w ww. ja v a 2 s . c o m JSONObject resonatorLimits = json.getJSONObject("resonatorLimits"); JSONArray bands = resonatorLimits.getJSONArray("bands"); mBands = new ArrayList<Band>(); for (int i = 0; i < bands.length(); i++) { JSONObject band = bands.getJSONObject(i); Band newBand = new Band(); newBand.applicableLevels = getIntArray(band, "applicableLevels"); newBand.remaining = band.getInt("remaining"); mBands.add(newBand); } mCanPlayerRemoveMod = json.getBoolean("canPlayerRemoveMod"); mMaxModsPerPlayer = json.getInt("maxModsPerPlayer"); }
From source file:com.foxykeep.datadroidpoc.data.factory.PhoneListFactory.java
public static ArrayList<Phone> parseResult(String wsResponse) throws DataException { ArrayList<Phone> phoneList = new ArrayList<Phone>(); try {//from w w w . java 2s. c o m JSONObject parser = new JSONObject(wsResponse); JSONObject jsonRoot = parser.getJSONObject(JSONTag.CRUD_PHONE_LIST_ELEM_PHONES); JSONArray jsonPhoneArray = jsonRoot.getJSONArray(JSONTag.CRUD_PHONE_LIST_ELEM_PHONE); int size = jsonPhoneArray.length(); for (int i = 0; i < size; i++) { JSONObject jsonPhone = jsonPhoneArray.getJSONObject(i); Phone phone = new Phone(); phone.serverId = jsonPhone.getLong(JSONTag.CRUD_PHONE_LIST_ELEM_ID); phone.name = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_NAME); phone.manufacturer = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_MANUFACTURER); phone.androidVersion = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_ANDROID_VERSION); phone.screenSize = jsonPhone.getDouble(JSONTag.CRUD_PHONE_LIST_ELEM_SCREEN_SIZE); phone.price = jsonPhone.getInt(JSONTag.CRUD_PHONE_LIST_ELEM_PRICE); phoneList.add(phone); } } catch (JSONException e) { Log.e(TAG, "JSONException", e); throw new DataException(e); } return phoneList; }
From source file:org.collectionspace.chain.csp.webui.record.RecordSearchList.java
private boolean morePermissions(JSONObject permissionResults, String key) throws JSONException { boolean result = false; if (permissionResults.has("pagination")) { JSONObject pagination = permissionResults.getJSONObject("pagination"); JSONArray separatelists = pagination.getJSONArray("separatelists"); String[] permissionsList = (String[]) separatelists.get(0); ///*from www . j a v a 2 s .c o m*/ // If the permissionsList is not empty then there still might // be another page of permissions, so we'll return true // if (permissionsList != null && permissionsList.length > 0) { result = true; } } // // Just to be safe, we'll also return true if we found items in the result list. // if (permissionResults.has(key) && permissionResults.getJSONArray(key).length() > 0) { result = true; } return result; }
From source file:org.collectionspace.chain.csp.webui.record.RecordSearchList.java
private JSONObject showReports(JSONObject data, String type, String key) throws JSONException { JSONObject results = new JSONObject(); JSONArray list = new JSONArray(); JSONArray names = new JSONArray(); if (data.has(key)) { JSONArray ja = data.getJSONArray(key); for (int j = 0; j < ja.length(); j++) { list.put(ja.getJSONObject(j).getString("csid")); names.put(ja.getJSONObject(j).getString("number")); }/*from w ww .ja v a 2 s . c o m*/ results.put("reportlist", list); results.put("reportnames", names); } return results; }
From source file:org.collectionspace.chain.csp.webui.record.RecordSearchList.java
private JSONObject showBatches(JSONObject data, String type, String key) throws JSONException { JSONObject results = new JSONObject(); JSONArray list = new JSONArray(); JSONArray names = new JSONArray(); JSONArray newFocuses = new JSONArray(); if (data.has(key)) { JSONArray ja = data.getJSONArray(key); for (int j = 0; j < ja.length(); j++) { list.put(ja.getJSONObject(j).getString("csid")); names.put(ja.getJSONObject(j).getString("number")); JSONObject summarylist = ja.getJSONObject(j).getJSONObject("summarylist"); newFocuses.put(summarylist.getBoolean("createsNewFocus")); }/*from w w w . java 2 s . c o m*/ results.put("batchlist", list); results.put("batchnames", names); results.put("batchnewfocuses", newFocuses); } return results; }
From source file:com.tassadar.multirommgr.installfragment.UbuntuImage.java
public UbuntuImage(JSONObject img) throws JSONException { version = img.getInt("version"); description = img.getString("description"); JSONArray f = img.getJSONArray("files"); for (int i = 0; i < f.length(); ++i) { JSONObject file = f.getJSONObject(i); files.add(new UbuntuFile(file)); }/*from www .j a v a2 s .c om*/ Collections.sort(files, this); }
From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java
public void onGetObject(Object object, String tag) { Boolean hasImages = false;/* w ww . j a v a 2 s .co m*/ JSONObject imagesData = (JSONObject) object; try { JSONArray imageArray = imagesData.getJSONArray("data"); for (int i = 0; i < imageArray.length(); i++) { JSONObject imageData = imageArray.getJSONObject(i); Log.d("adding album...", imageData.getString("id")); if (!imageData.getString(ImgurHoloActivity.IMAGE_DATA_COVER).equals("[[")) { urls.add("http://imgur.com/" + imageData.getString(ImgurHoloActivity.IMAGE_DATA_COVER) + "m.png"); ids.add(imageData.getString("id")); } } hasImages = imageArray.length() > 0; } catch (JSONException e) { Log.e("Error!", e.toString()); imagesData = null; } if (hasImages) imageAdapter.notifyDataSetChanged(); else if (imagesData != null) noImageView.setVisibility(View.VISIBLE); else errorText.setVisibility(View.VISIBLE); if (mPullToRefreshLayout != null) mPullToRefreshLayout.setRefreshComplete(); }