Java Code Examples for android.util.JsonReader#hasNext()
The following examples show how to use
android.util.JsonReader#hasNext() .
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: 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 2
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@NonNull private static CrashlyticsReport.FilesPayload.File parseFile(@NonNull JsonReader jsonReader) throws IOException { final CrashlyticsReport.FilesPayload.File.Builder builder = CrashlyticsReport.FilesPayload.File.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "filename": builder.setFilename(jsonReader.nextString()); break; case "contents": builder.setContents(Base64.decode(jsonReader.nextString(), Base64.NO_WRAP)); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 3
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@NonNull private static CustomAttribute parseCustomAttribute(@NonNull JsonReader jsonReader) throws IOException { final CustomAttribute.Builder builder = CustomAttribute.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "key": builder.setKey(jsonReader.nextString()); break; case "value": builder.setValue(jsonReader.nextString()); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 4
Source File: GeoMultiPolygon.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void setCoordinatesFromJSONStream(JsonReader reader, int crs) throws IOException { setCRS(crs); reader.beginArray(); while (reader.hasNext()){ GeoPolygon polygon = new GeoPolygon(); polygon.setCoordinatesFromJSONStream(reader, crs); mGeometries.add(polygon); } reader.endArray(); }
Example 5
Source File: NGWVectorLayer.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
protected void readFeatures(JsonReader reader, List<Feature> features) throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError { reader.beginArray(); while (reader.hasNext()) { final Feature feature = NGWUtil.readNGWFeature(reader, getFields(), mCRS); if (feature.getGeometry() == null || !feature.getGeometry().isValid()) continue; features.add(feature); } reader.endArray(); }
Example 6
Source File: JSONParser.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private static List<ZCashTransactionDetails_taddr> readTxArray(JsonReader reader) throws IOException { List<ZCashTransactionDetails_taddr> txs = new LinkedList<>(); reader.beginArray(); while (reader.hasNext()) { txs.add(readTx(reader)); } reader.endArray(); return txs; }
Example 7
Source File: BlocklistProcessor.java From focus-android with Mozilla Public License 2.0 | 5 votes |
private static void extractCategory(final JsonReader reader, final UrlListCallback callback) throws IOException { reader.beginArray(); while (reader.hasNext()) { extractSite(reader, callback); } reader.endArray(); }
Example 8
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@NonNull private static Event.Application.Execution parseEventExecution(@NonNull JsonReader jsonReader) throws IOException { final Event.Application.Execution.Builder builder = Event.Application.Execution.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "threads": builder.setThreads( parseArray(jsonReader, CrashlyticsReportJsonTransform::parseEventThread)); break; case "exception": builder.setException(parseEventExecutionException(jsonReader)); break; case "signal": builder.setSignal(parseEventSignal(jsonReader)); break; case "binaries": builder.setBinaries( parseArray(jsonReader, CrashlyticsReportJsonTransform::parseEventBinaryImage)); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 9
Source File: AboutJSONParser.java From pivaa with GNU General Public License v3.0 | 5 votes |
/** * Iterating objects * @param reader * @return * @throws IOException */ private ArrayList<AboutRecord> readMessagesArray(JsonReader reader) throws IOException { ArrayList<AboutRecord> messages = new ArrayList<AboutRecord>(); reader.beginArray(); while (reader.hasNext()) { messages.add(readMessage(reader)); } reader.endArray(); return messages; }
Example 10
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@NonNull private static Event.Application.Execution.Signal parseEventSignal(@NonNull JsonReader jsonReader) throws IOException { final Event.Application.Execution.Signal.Builder builder = Event.Application.Execution.Signal.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "name": builder.setName(jsonReader.nextString()); break; case "code": builder.setCode(jsonReader.nextString()); break; case "address": builder.setAddress(jsonReader.nextLong()); break; default: jsonReader.skipValue(); break; } } jsonReader.endObject(); return builder.build(); }
Example 11
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 12
Source File: LoadTags.java From NClientV2 with Apache License 2.0 | 5 votes |
private void readTags(JsonReader reader) throws IOException{ reader.beginArray(); while (reader.hasNext()) { Tag tt = new Tag(reader); if (tt.getType() != TagType.LANGUAGE && tt.getType() != TagType.CATEGORY) { Login.addOnlineTag(tt); if (adapter != null) adapter.addItem(); } } }
Example 13
Source File: GeoGeometryCollection.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void setCoordinatesFromJSONStream(JsonReader reader, int crs) throws IOException { setCRS(crs); reader.beginArray(); while (reader.hasNext()){ GeoGeometry geometry = GeoGeometryFactory.fromJsonStream(reader, crs); if(null != geometry) mGeometries.add(geometry); } reader.endArray(); }
Example 14
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 15
Source File: GeoJSONUtil.java From android_maplib with GNU Lesser General Public License v3.0 | 4 votes |
public static void fillLayerFromGeoJSONStream(VectorLayer layer, InputStream in, int srs, IProgressor progressor) throws IOException, NGException { int streamSize = in.available(); if(null != progressor){ progressor.setIndeterminate(false); progressor.setMax(streamSize); progressor.setMessage(layer.getContext().getString(R.string.start_fill_layer) + " " + layer.getName()); } SQLiteDatabase db = null; if(layer.getFields() != null && layer.getFields().isEmpty()){ db = DatabaseContext.getDbForLayer(layer); } JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8")); boolean isWGS84 = srs == GeoConstants.CRS_WGS84; long counter = 0; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if(name.equals(GeoConstants.GEOJSON_TYPE_FEATURES)){ reader.beginArray(); while (reader.hasNext()) { Feature feature = readGeoJSONFeature(reader, layer, isWGS84); if (null != feature) { if(layer.getFields() != null && !layer.getFields().isEmpty()){ if (feature.getGeometry() != null) layer.create(feature.getGeometry().getType(), feature.getFields()); db = DatabaseContext.getDbForLayer(layer); } if(feature.getGeometry() != null) { layer.createFeatureBatch(feature, db); if(null != progressor){ if (progressor.isCanceled()) { layer.save(); return; } progressor.setValue(streamSize - in.available()); progressor.setMessage(layer.getContext().getString(R.string.process_features) + ": " + counter++); } } } } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); reader.close(); //if(null != db) // db.close(); // return pragma to init layer.save(); }
Example 16
Source File: CrashlyticsReportJsonTransform.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
@NonNull private static CrashlyticsReport.Session parseSession(@NonNull JsonReader jsonReader) throws IOException { final CrashlyticsReport.Session.Builder builder = CrashlyticsReport.Session.builder(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); switch (name) { case "generator": builder.setGenerator(jsonReader.nextString()); break; case "identifier": builder.setIdentifierFromUtf8Bytes( Base64.decode(jsonReader.nextString(), Base64.NO_WRAP)); break; case "startedAt": builder.setStartedAt(jsonReader.nextLong()); break; case "endedAt": builder.setEndedAt(jsonReader.nextLong()); break; case "crashed": builder.setCrashed(jsonReader.nextBoolean()); break; case "user": builder.setUser(parseUser(jsonReader)); break; case "app": builder.setApp(parseApp(jsonReader)); break; case "os": builder.setOs(parseOs(jsonReader)); break; case "device": builder.setDevice(parseDevice(jsonReader)); break; case "events": builder.setEvents(parseArray(jsonReader, CrashlyticsReportJsonTransform::parseEvent)); break; case "generatorType": builder.setGeneratorType(jsonReader.nextInt()); 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 ZCashTransactionOutput readTxSingleOutput(JsonReader reader) throws IOException { ZCashTransactionOutput output = new ZCashTransactionOutput(); reader.beginObject(); //output while (reader.peek() != JsonToken.END_OBJECT) { String name = reader.nextName(); switch (name) { case N: output.n = reader.nextLong(); break; case SCRIPTPUBKEY: reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { name = reader.nextName(); switch (name) { case ADDRESSES: reader.beginArray(); while (reader.hasNext()) { output.address = reader.nextString(); } reader.endArray(); break; case ASM: output.asm = reader.nextString(); break; case HEX: output.hex = reader.nextString(); break; case REQSIGS: output.regSigs = reader.nextLong(); break; case TYPE: output.type = reader.nextString(); break; default: reader.skipValue(); } } reader.endObject(); break; case VALUE: output.value = Double.valueOf(reader.nextDouble() * 1e8).longValue(); break; case VALUEZAT: output.value = reader.nextLong(); break; default: reader.skipValue(); } } reader.endObject(); //output end return output; }
Example 18
Source File: BatchManagerTest.java From background-geolocation-android with Apache License 2.0 | 4 votes |
private List<BackgroundLocation> readLocationsArray(JsonReader reader) throws IOException { List<BackgroundLocation> locations = new ArrayList<BackgroundLocation>(); reader.beginArray(); while (reader.hasNext()) { BackgroundLocation l = new BackgroundLocation(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("id")) { l.setLocationId(reader.nextLong()); } else if (name.equals("time")) { l.setTime(reader.nextLong()); } else if (name.equals("latitude")) { l.setLatitude(reader.nextDouble()); } else if (name.equals("longitude")) { l.setLongitude(reader.nextDouble()); } else if (name.equals("accuracy")) { l.setAccuracy((float)reader.nextDouble()); } else if (name.equals("speed")) { l.setSpeed((float)reader.nextDouble()); } else if (name.equals("bearing")) { l.setBearing((float)reader.nextDouble()); } else if (name.equals("altitude")) { l.setAltitude(reader.nextDouble()); } else if (name.equals("radius")) { JsonToken token = reader.peek(); if (token != JsonToken.NULL) { l.setRadius((float)reader.nextDouble()); } else { reader.skipValue(); } } else if (name.equals("provider")) { l.setProvider(reader.nextString()); } else if (name.equals("locationProvider")) { l.setLocationProvider(reader.nextInt()); } else { reader.skipValue(); } } reader.endObject(); locations.add(l); } reader.endArray(); return locations; }
Example 19
Source File: Utility.java From SoldierWeather with Apache License 2.0 | 4 votes |
/** * 保存到数据库 * @param reader * @return */ private static boolean saveAreaToDatabase(JsonReader reader) { LogUtil.log("Utility", "saveAreaToDatabase", LogUtil.NOTHING); String provinceName = null; String cityName = null; String districtName = null; List<String> provinceNames = new ArrayList<>(); List<String> cityNames = new ArrayList<>(); boolean changedProvince = false; boolean changedCity = false; int provinceId = 0; int cityId = 0; int districtId = 0; Province previousProvince = new Province(); City previousCity = new City(); try { reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { String nodeName = reader.nextName(); if (nodeName.equals("province")) { provinceName = reader.nextString().trim(); if (!provinceNames.contains(provinceName)) { provinceNames.add(provinceName); changedProvince = true; provinceId++; } } else if (nodeName.equals("city")) { cityName = reader.nextString().trim(); if (!cityNames.contains(cityName)) { cityNames.add(cityName); changedCity = true; cityId++; LogUtil.log("Utility", "********changedCity = " + changedCity, LogUtil.NOTHING); } } else if (nodeName.equals("district")) { districtName = reader.nextString().trim(); } else { reader.skipValue(); } } reader.endObject(); LogUtil.log("Utility", "\nprovince_name = " + provinceName + "\ncity_name = " + cityName + "\ndistrict_name = " + districtName, LogUtil.NOTHING); if (changedProvince) { Province province = new Province(); province.setId(provinceId); province.setProvinceName(provinceName); previousProvince = province; soldierWeatherDB.saveProvince(province); changedProvince = false; LogUtil.log("Utility", "province_id = " + province.getId() + "\tprovince_name = " + province.getProvinceName(), LogUtil.NOTHING); } if (changedCity) { LogUtil.log("Utility", "########changedCity = " + changedCity, LogUtil.NOTHING); City city = new City(); city.setId(cityId); city.setCityName(cityName); city.setProvinceId(previousProvince.getId()); previousCity = city; soldierWeatherDB.saveCity(city); changedCity = false; LogUtil.log("Utility", "city_id = " + city.getId() + "\tcity_name = " + city.getCityName() + "\tprovince_id = " + city.getProvinceId(), LogUtil.NOTHING); } District district = new District(); districtId++; district.setId(districtId); district.setDistrictName(districtName); district.setCityId(previousCity.getId()); soldierWeatherDB.saveDistrict(district); LogUtil.log("Utility", "district_id = " + district.getId() + "\tdistrict_name = " + district.getDistrictName() + "\tcity_id = " + district.getCityId(), LogUtil.NOTHING); } reader.endArray(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }