Java Code Examples for android.util.JsonReader#endObject()
The following examples show how to use
android.util.JsonReader#endObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NGWUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 6 votes |
private static void readNGWFeatureAttachments(Feature feature, JsonReader reader) throws IOException { //add extensions reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("attachment") && reader.peek() != JsonToken.NULL) { reader.beginArray(); while (reader.hasNext()) { readNGWFeatureAttachment(feature, reader); } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); }
Example 2
Source File: BlocklistProcessor.java From focus-android with Mozilla Public License 2.0 | 6 votes |
public static Map<String, Trie> loadCategoryMap(final JsonReader reader, final Map<String, Trie> categoryMap, final ListType listType) throws IOException { reader.beginObject(); while (reader.hasNext()) { final String name = reader.nextName(); if (name.equals("categories")) { extractCategories(reader, categoryMap, listType); } else { reader.skipValue(); } } reader.endObject(); return categoryMap; }
Example 3
Source File: GalleryData.java From NClientV2 with Apache License 2.0 | 6 votes |
private void parseJSON(JsonReader jr) throws IOException { jr.beginObject(); while(jr.peek()!= JsonToken.END_OBJECT){ switch(jr.nextName()){ case "upload_date":uploadDate=new Date(jr.nextLong()*1000);break; case "num_favorites":favoriteCount=jr.nextInt();break; case "media_id":mediaId=jr.nextInt();break; case "title":readTitles(jr);break; case "images":readImages(jr); break; case "tags":readTags(jr);break; case "id":id=jr.nextInt();break; case "num_pages":pageCount=jr.nextInt();break; case "error":jr.skipValue(); valid=false;break; default:jr.skipValue();break; } } jr.endObject(); }
Example 4
Source File: GalleryData.java From NClientV2 with Apache License 2.0 | 6 votes |
private void readImages(JsonReader jr) throws IOException { int actualPage=0; jr.beginObject(); while (jr.peek()!=JsonToken.END_OBJECT){ switch (jr.nextName()){ case "cover": cover= new Page(ImageType.COVER,jr); break; case "pages": jr.beginArray(); while(jr.hasNext()) pages.add(new Page(ImageType.PAGE,jr,actualPage++)); jr.endArray(); break; case "thumbnail": thumbnail= new Page(ImageType.THUMBNAIL,jr); break; default: jr.skipValue(); break; } } jr.endObject(); pages.trimToSize(); }
Example 5
Source File: AndroidPlacesApiJsonParser.java From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License | 6 votes |
PlaceGeometry readGeometry(JsonReader reader) throws IOException { double lat = -1.0; double lng = -1.0; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "lat": lat = reader.nextDouble(); break; case "lng": lng = reader.nextDouble(); break; default: reader.skipValue(); break; } } reader.endObject(); return new PlaceGeometry(new PlaceLocation(lat, lng)); }
Example 6
Source File: JsonUtils.java From openboard with GNU General Public License v3.0 | 5 votes |
public static List<Object> jsonStrToList(final String s) { final ArrayList<Object> list = new ArrayList<>(); final JsonReader reader = new JsonReader(new StringReader(s)); try { reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { final String name = reader.nextName(); if (name.equals(INTEGER_CLASS_NAME)) { list.add(reader.nextInt()); } else if (name.equals(STRING_CLASS_NAME)) { list.add(reader.nextString()); } else { Log.w(TAG, "Invalid name: " + name); reader.skipValue(); } } reader.endObject(); } reader.endArray(); return list; } catch (final IOException e) { } finally { close(reader); } return Collections.emptyList(); }
Example 7
Source File: DecisionTree.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
private static void readJsonCheckboxes(final JsonReader reader, final Question question) throws IOException { reader.beginObject(); while (reader.hasNext()) { final String answerId = reader.nextName(); //Get the previously created checkbox from the decision tree and add the translated text: final Checkbox checkbox = question.getCheckbox(answerId); if (checkbox != null) { checkbox.setText(reader.nextString()); } else { reader.skipValue(); } } reader.endObject(); }
Example 8
Source File: DecisionTree.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
private void readJsonQuestions(final JsonReader reader) throws IOException { reader.beginObject(); while (reader.hasNext()) { final String questionId = reader.nextName(); final Question question = questionsMap.get(questionId); if (question != null) { readJsonQuestion(reader, question); } else { reader.skipValue(); } } reader.endObject(); }
Example 9
Source File: AndroidPlacesApiJsonParser.java From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License | 5 votes |
List<PlacePhoto> readPhotosArray(JsonReader reader) throws IOException { List<PlacePhoto> photos = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { int height = -1; int width = -1; String photoReference = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "height": height = reader.nextInt(); break; case "width": width = reader.nextInt(); break; case "photo_reference": photoReference = reader.nextString(); break; default: reader.skipValue(); break; } } reader.endObject(); photos.add(new PlacePhoto(height, width, photoReference)); } reader.endArray(); return photos; }
Example 10
Source File: JsonUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
public static List<Object> jsonStrToList(final String s) { final ArrayList<Object> list = new ArrayList<>(); final JsonReader reader = new JsonReader(new StringReader(s)); try { reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { final String name = reader.nextName(); if (name.equals(INTEGER_CLASS_NAME)) { list.add(reader.nextInt()); } else if (name.equals(STRING_CLASS_NAME)) { list.add(reader.nextString()); } else { Log.w(TAG, "Invalid name: " + name); reader.skipValue(); } } reader.endObject(); } reader.endArray(); return list; } catch (final IOException e) { } finally { close(reader); } return Collections.<Object>emptyList(); }
Example 11
Source File: DecisionTree.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
private static void readJsonAnswers(final JsonReader reader, final Question question) throws IOException { reader.beginObject(); while (reader.hasNext()) { final String answerId = reader.nextName(); //Get the previously created answer from the decision tree and add the translated text: final Answer answer = question.getAnswer(answerId); if (answer != null) { answer.setText(reader.nextString()); } else { reader.skipValue(); } } reader.endObject(); }
Example 12
Source File: MyViewModel.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
public Earthquake readEarthquake(JsonReader reader) throws IOException { String id = null; Location location = null; Earthquake earthquakeProperties = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("id")) { // The ID is stored as a value. id = reader.nextString(); } else if (name.equals("geometry")) { // The location is stored as a geometry object // that must be parsed. location = readLocation(reader); } else if (name.equals("properties")) { // Most of the earthquake details are stored as a // properties object that must be parsed. earthquakeProperties = readEarthquakeProperties(reader); } else { reader.skipValue(); } } reader.endObject(); // Construct a new Earthquake based on the parsed details. return new Earthquake(id, earthquakeProperties.getDate(), earthquakeProperties.getDetails(), location, earthquakeProperties.getMagnitude(), earthquakeProperties.getLink()); }
Example 13
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@NonNull private static Event.Application.Execution.Thread.Frame parseEventFrame( @NonNull JsonReader jsonReader) throws IOException { final Event.Application.Execution.Thread.Frame.Builder builder = Event.Application.Execution.Thread.Frame.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "importance": builder.setImportance(jsonReader.nextInt()); break; case "file": builder.setFile(jsonReader.nextString()); break; case "offset": builder.setOffset(jsonReader.nextLong()); break; case "pc": builder.setPc(jsonReader.nextLong()); break; case "symbol": builder.setSymbol(jsonReader.nextString()); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 14
Source File: JSONParser.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private static ZCashTransactionInput readTxSingleInput(JsonReader reader) throws IOException { ZCashTransactionInput input = new ZCashTransactionInput(); reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { String name = reader.nextName(); switch (name) { case COINBASE: input.coinbase = reader.nextString(); break; case SEQUENCE: input.sequence = reader.nextLong(); break; case TXID: input.txid = reader.nextString(); break; case VOUT: input.n = reader.nextLong(); break; case SCRIPTSIG: reader.skipValue(); break; case RETRIEVEDVOUT: input.copyDataFrom(readTxSingleOutput(reader)); break; default: reader.skipValue(); } } reader.endObject(); return input; }
Example 15
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@NonNull private static CrashlyticsReport.Session.Application parseApp(@NonNull JsonReader jsonReader) throws IOException { final CrashlyticsReport.Session.Application.Builder builder = CrashlyticsReport.Session.Application.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "identifier": builder.setIdentifier(jsonReader.nextString()); break; case "version": builder.setVersion(jsonReader.nextString()); break; case "displayVersion": builder.setDisplayVersion(jsonReader.nextString()); break; case "installationUuid": builder.setInstallationUuid(jsonReader.nextString()); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 16
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
@NonNull private static CrashlyticsReport.Session.Device parseDevice(@NonNull JsonReader jsonReader) throws IOException { final CrashlyticsReport.Session.Device.Builder builder = CrashlyticsReport.Session.Device.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "arch": builder.setArch(jsonReader.nextInt()); break; case "model": builder.setModel(jsonReader.nextString()); break; case "cores": builder.setCores(jsonReader.nextInt()); break; case "ram": builder.setRam(jsonReader.nextLong()); break; case "diskSpace": builder.setDiskSpace(jsonReader.nextLong()); break; case "simulator": builder.setSimulator(jsonReader.nextBoolean()); break; case "state": builder.setState(jsonReader.nextInt()); break; case "manufacturer": builder.setManufacturer(jsonReader.nextString()); break; case "modelClass": builder.setModelClass(jsonReader.nextString()); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 17
Source File: JSONParser.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
private static ZCashTransactionDetails_taddr readTx(JsonReader reader) throws IOException, IllegalStateException { ZCashTransactionDetails_taddr tx = new ZCashTransactionDetails_taddr(); if(reader.peek() != JsonToken.BEGIN_OBJECT) { throw new IOException("Cannot parse JSON"); } reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { String name = reader.nextName(); switch (name) { case HASH: tx.hash = reader.nextString(); break; case MAINCHAIN: tx.mainChain = reader.nextBoolean(); break; case FEE: tx.fee = Double.valueOf(reader.nextDouble() * 1e8).longValue(); break; case TYPE: tx.type = reader.nextString(); break; case SHIELDED: tx.shielded = reader.nextBoolean(); break; case INDEX: tx.index = reader.nextLong(); break; case BLOCKHASH: tx.blockHash = reader.nextString(); break; case BLOCKHEIGHT: tx.blockHeight = reader.nextLong(); break; case VERSION: tx.version = reader.nextLong(); break; case LOCKTIME: tx.locktime = reader.nextLong(); break; case TIME: tx.time = reader.nextLong(); break; case TIMESTAMP: tx.timestamp = reader.nextLong(); break; case VIN: tx.vin = readTxInputs(reader); break; case VOUT: tx.vout = readTxOutputs(reader, null); break; case VJOINSPLIT: skipJoinSplits(reader); break; case VALUE: tx.value = Double.valueOf(reader.nextDouble() * 1e8).longValue(); break; case OUTPUTVALUE: tx.outputValue = Double.valueOf(reader.nextDouble() * 1e8).longValue(); break; case SHIELDEDVALUE: tx.shieldedValue = Double.valueOf(reader.nextDouble() * 1e8).longValue(); break; default: reader.skipValue(); } } reader.endObject(); return tx; }
Example 18
Source File: SampleChooserActivity.java From ExoPlayer-Offline with Apache License 2.0 | 4 votes |
private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOException { String sampleName = null; String uri = null; String extension = null; UUID drmUuid = null; String drmLicenseUrl = null; String[] drmKeyRequestProperties = null; boolean preferExtensionDecoders = false; ArrayList<UriSample> playlistSamples = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case "name": sampleName = reader.nextString(); break; case "uri": uri = reader.nextString(); break; case "extension": extension = reader.nextString(); break; case "drm_scheme": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_scheme"); drmUuid = getDrmUuid(reader.nextString()); break; case "drm_license_url": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_license_url"); drmLicenseUrl = reader.nextString(); break; case "drm_key_request_properties": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: drm_key_request_properties"); ArrayList<String> drmKeyRequestPropertiesList = new ArrayList<>(); reader.beginObject(); while (reader.hasNext()) { drmKeyRequestPropertiesList.add(reader.nextName()); drmKeyRequestPropertiesList.add(reader.nextString()); } reader.endObject(); drmKeyRequestProperties = drmKeyRequestPropertiesList.toArray(new String[0]); break; case "prefer_extension_decoders": Assertions.checkState(!insidePlaylist, "Invalid attribute on nested item: prefer_extension_decoders"); preferExtensionDecoders = reader.nextBoolean(); break; case "playlist": Assertions.checkState(!insidePlaylist, "Invalid nesting of playlists"); playlistSamples = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { playlistSamples.add((UriSample) readEntry(reader, true)); } reader.endArray(); break; default: throw new ParserException("Unsupported attribute name: " + name); } } reader.endObject(); if (playlistSamples != null) { UriSample[] playlistSamplesArray = playlistSamples.toArray( new UriSample[playlistSamples.size()]); return new PlaylistSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders, playlistSamplesArray); } else { return new UriSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders, uri, extension); } }
Example 19
Source File: SampleChooserActivity.java From ExoPlayer-Offline with Apache License 2.0 | 4 votes |
private Sample readOfflineEntry(JsonReader reader) throws IOException { String sampleName = null; String downloadUri = null; String offlineUri = null; String extension = null; UUID drmUuid = null; String drmLicenseUrl = null; String[] drmKeyRequestProperties = null; boolean preferExtensionDecoders = false; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case "name": sampleName = reader.nextString(); break; case "download_uri": downloadUri = reader.nextString(); break; case "offline_uri": offlineUri = reader.nextString(); break; case "extension": extension = reader.nextString(); break; case "drm_scheme": drmUuid = getDrmUuid(reader.nextString()); break; case "drm_license_url": drmLicenseUrl = reader.nextString(); break; case "drm_key_request_properties": ArrayList<String> drmKeyRequestPropertiesList = new ArrayList<>(); reader.beginObject(); while (reader.hasNext()) { drmKeyRequestPropertiesList.add(reader.nextName()); drmKeyRequestPropertiesList.add(reader.nextString()); } reader.endObject(); drmKeyRequestProperties = drmKeyRequestPropertiesList.toArray(new String[0]); break; case "prefer_extension_decoders": preferExtensionDecoders = reader.nextBoolean(); break; default: throw new ParserException("Unsupported attribute name: " + name); } } reader.endObject(); return new OfflineSample(sampleName,drmUuid,drmLicenseUrl,drmKeyRequestProperties, preferExtensionDecoders,offlineUri,downloadUri); }
Example 20
Source File: AboutDialog.java From MediaNotification with Apache License 2.0 | 4 votes |
@Override public void run() { try { HttpURLConnection request = (HttpURLConnection) new URL("https://api.github.com/repos/TheAndroidMaster/MediaNotification/contributors").openConnection(); request.connect(); JsonReader reader = new JsonReader(new InputStreamReader((InputStream) request.getContent())); reader.setLenient(true); reader.beginArray(); reader.skipValue(); while (reader.hasNext()) { reader.beginObject(); String name = null, imageUrl = null, url = null; while (reader.hasNext()) { switch (reader.nextName()) { case "login": name = reader.nextString(); break; case "avatar_url": imageUrl = reader.nextString(); break; case "html_url": url = reader.nextString(); break; default: reader.skipValue(); } } contributors.add(new ContributorData(name, imageUrl, url)); reader.endObject(); } reader.endArray(); } catch (Exception ignored) { } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { AboutDialog dialog = dialogReference.get(); if (dialog != null) { dialog.contributorView.getAdapter().notifyDataSetChanged(); for (final ContributorData contributor : contributors) { new ContributorThread(dialog, contributor).start(); } } } }); }