private List<Post> loadCatalog(JsonReader reader) throws Exception { ArrayList<Post> list = new ArrayList<>(); reader.beginArray(); // Array of pages while (reader.hasNext()) { reader.beginObject(); // Page object while (reader.hasNext()) { if (reader.nextName().equals("threads")) { reader.beginArray(); // Threads array while (reader.hasNext()) { list.add(readPostObject(reader)); } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); } reader.endArray(); return list; }
/** * Parses the 2D JSONArray of frame rectangles and populates {@code mRectangles}. * * @param reader The JsonReader reading the JSON metadata. * @throws IOException */ private void parseFrameRectangles(JsonReader reader) throws IOException { ArrayList<ArrayList<Integer>> allFrameRectangles = new ArrayList<ArrayList<Integer>>(); int frameCount = 0; reader.beginArray(); // Start reading 2D rectangles array. while (reader.hasNext()) { ArrayList<Integer> frameRectangles = new ArrayList<Integer>(); reader.beginArray(); // Start reading frame array. while (reader.hasNext()) { frameRectangles.add(reader.nextInt()); } reader.endArray(); // Stop reading frame array. allFrameRectangles.add(frameRectangles); frameCount++; } reader.endArray(); // Stop reading 2D rectangles array. // Convert 2D ArrayList to int[][]. mRectangles = new int[frameCount][]; for (int i = 0; i < frameCount; i++) { ArrayList<Integer> frameRectangles = allFrameRectangles.get(i); int[] frameRectanglesArray = new int[frameRectangles.size()]; for (int j = 0; j < frameRectangles.size(); j++) { frameRectanglesArray[j] = frameRectangles.get(j); } mRectangles[i] = frameRectanglesArray; } }
private void readFeaturesArray(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { readErthquake(reader); } reader.endArray(); }
public ArrayList<Promotion> parsePromotionList(JsonReader jsonReader) { ArrayList<Promotion> promoList = new ArrayList<Promotion>(); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals(JSON_KEY_PROMOTIONS) && jsonReader.peek() != JsonToken.NULL) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Promotion promo = parsePromotion(jsonReader); if (promo != null) { promoList.add(promo); } } jsonReader.endArray(); } else { jsonReader.skipValue(); } } jsonReader.endObject(); } catch (IOException e) { } return promoList; }
/** * Parses the raw JSON resource specified by {@code metadataResId}. The JSON is expected to be in * this format: { "apiVersion": <version number (string)>, "densities": [ { "density": <density * (int)>, "width": <unscaled sprite width (int)>, "height": <unscaled sprite height (int)>, * "rectangles": [ [<list of ints for frame 0>], [<list of ints for frame 1>], ...... ] }, { * "density": <density (int)>, "width": <unscaled sprite width (int)>, "height": <unscaled sprite * height (int)>, "rectangles": [ [<list of ints for frame 0>], [<list of ints for frame 1>], * ...... ] }, ...... ] } * * @param metadataResId The id of the raw resource containing JSON to parse. * @param bitmapDensity The density of the unscaled {@link Bitmap} that was loaded. * @param resources A {@link Resources} instance to load assets from. * @throws IOException */ @VisibleForTesting void parseMetadata(int metadataResId, int bitmapDensity, Resources resources) throws IOException { InputStream inputStream = resources.openRawResource(metadataResId); JsonReader reader = new JsonReader(new InputStreamReader(inputStream)); try { reader.beginObject(); // Start reading top-level object. // Check apiVersion. String name = reader.nextName(); assert name.equals("apiVersion"); String version = reader.nextString(); assert version.equals("1.0"); // Parse array of densities. name = reader.nextName(); assert name.equals("densities"); reader.beginArray(); // Start reading array of densities. while (reader.hasNext()) { reader.beginObject(); // Start reading object for this density. boolean foundDensity = parseMetadataForDensity(reader, bitmapDensity); reader.endObject(); // Stop reading object for this density. if (foundDensity) break; } } finally { reader.close(); inputStream.close(); } }
/** Parse metric array */ void parseArray() throws IOException { _reader.beginArray(); while (_reader.hasNext()) { parseBody(); } _reader.endArray(); }
private static String[] getParametersFromIntent(Intent intent) { if (intent == null) { return null; } String[] parameters = intent.getStringArrayExtra("parameters"); if (parameters != null) { return parameters; } String encodedParameters = intent.getStringExtra("encodedParameters"); if (encodedParameters != null) { JsonReader reader = new JsonReader(new StringReader(encodedParameters)); List<String> parametersList = new ArrayList<String>(); try { reader.beginArray(); while (reader.hasNext()) { parametersList.add(reader.nextString()); } reader.endArray(); reader.close(); return parametersList.toArray(new String[parametersList.size()]); } catch (IOException e) { Log.w(TAG, e.getMessage(), e); } } return null; }
private void parseWeatherFormWeather(JsonReader reader) throws IOException { Log.d(TAG, "Entering parseWeatherFormWeather"); reader.beginArray(); reader.beginObject(); try { while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case JsonWeatherTokens.DESCRIPTION: weatherData.setWeather(reader.nextString()); break; case JsonWeatherTokens.ICON: weatherData.setIcon(reader.nextString()); break; default: reader.skipValue(); break; } } } finally { reader.endObject(); reader.endArray(); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public ArrayList<Song> parseSongList(JsonReader jsonReader) { ArrayList<Song> songList = new ArrayList<Song>(); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals(JSON_KEY_RESULTS) && jsonReader.peek() != JsonToken.NULL) { jsonReader.beginArray(); while (jsonReader.hasNext()) { Song song = parseSong(jsonReader); if (song != null) { songList.add(song); } } jsonReader.endArray(); } else { jsonReader.skipValue(); } } jsonReader.endObject(); } catch (IOException e) { } return songList; }
private void readArticlesArray(List<SnippetListItem> listSnippetItems, JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { listSnippetItems.add(readArticleDetails(reader)); } reader.endArray(); }
public List<Image> readImagesArray(JsonReader reader) throws IOException { List<Image> images = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { images.add(readImage(reader)); } reader.endArray(); return images; }
public List<Msg> readMsgs(JsonReader reader) throws IOException { List<Msg> msgList = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { msgList.add(readMsg(reader)); } reader.endArray(); return msgList; }
private List<Source> readSources(JsonReader reader) throws IOException { List<Source> sourceList = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { sourceList.add(new Source(readSource(reader), null)); } reader.endArray(); return sourceList; }
private List readHitsArray(JsonReader reader) throws IOException { List hits = new ArrayList<FoodResult>(); reader.beginArray(); while (reader.hasNext()) { hits.add(readHitObject(reader)); } reader.endArray(); return hits; }
private List<LatLng> readLatLngArray(JsonReader reader) throws IOException { List<LatLng> latlngpath = new ArrayList(); reader.beginArray(); while (reader.hasNext()) { latlngpath.add(readLatLngPoint(reader)); } reader.endArray(); return latlngpath; }
public ArrayList readMessagesArray(JsonReader reader) throws IOException { ArrayList repos = new ArrayList(); reader.beginArray(); while (reader.hasNext()) { repos.add(readMessage(reader)); } reader.endArray(); return repos; }
private List<String> readSource(JsonReader reader) throws IOException { List<String> source = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { source.add(reader.nextString()); } reader.endArray(); return source; }
private List<SnippetListItem> readRecommendationsArray(JsonReader reader) throws IOException { List<SnippetListItem> listSnippetItems = new ArrayList<SnippetListItem>(); mNumArticles = 0; reader.beginArray(); while (reader.hasNext()) { readSnippetGroup(listSnippetItems, reader); } reader.endArray(); RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.NumArticles", mNumArticles); return listSnippetItems; }
private void readMessagesArray(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { readMessage(reader); key++; addToList(key, marker, polygon); } // while reader.endArray(); }
protected final void addThumbnailUrl(JsonReader jsonreader, ContentValues contentvalues, String s) throws IOException { jsonreader.beginArray(); do { if (!jsonreader.hasNext()) break; String s1 = parseObject(jsonreader, "url"); if (s1 == null) continue; contentvalues.put(s, s1); for (; jsonreader.hasNext(); jsonreader.skipValue()) ; break; } while (true); jsonreader.endArray(); }
private List<Post> loadBoard(JsonReader reader) throws Exception { ArrayList<Post> list = new ArrayList<>(); reader.beginObject(); // Threads array if (reader.nextName().equals("threads")) { reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); // Thread object if (reader.nextName().equals("posts")) { reader.beginArray(); list.add(readPostObject(reader)); // Only consume one post while (reader.hasNext()) reader.skipValue(); reader.endArray(); } else { reader.skipValue(); } reader.endObject(); } reader.endArray(); } else { reader.skipValue(); } reader.endObject(); return list; }
@Override public void deSerializeRepresentation(JsonReader sreader) throws IOException { sreader.beginObject(); Vector<StrokeData> strokes = new Vector<StrokeData>(); while (sreader.hasNext()) { sreader.nextName(); sreader.beginObject(); StrokeData stroke = new StrokeData(); while (sreader.hasNext()) { String name = sreader.nextName(); if (name.equals(SERIAL_COLOR)) { stroke.mColor = sreader.nextInt(); } else if (name.equals(SERIAL_RADIUS)) { stroke.mRadius = (float) sreader.nextDouble(); } else if (name.equals(SERIAL_TYPE)) { stroke.mType = (byte) sreader.nextInt(); } else if (name.equals(SERIAL_POINTS_COUNT)) { stroke.noPoints = sreader.nextInt(); } else if (name.equals(SERIAL_POINTS)) { int count = 0; sreader.beginArray(); while (sreader.hasNext()) { if ((count + 1) > stroke.mPoints.length) { stroke.mPoints = Arrays.copyOf(stroke.mPoints, count * 2); } stroke.mPoints[count++] = (float) sreader.nextDouble(); } stroke.mPath = new Path(); stroke.mPath.moveTo(stroke.mPoints[0], stroke.mPoints[1]); for (int i = 0; i < count; i += 2) { stroke.mPath.lineTo(stroke.mPoints[i], stroke.mPoints[i + 1]); } sreader.endArray(); strokes.add(stroke); } else { sreader.skipValue(); } } sreader.endObject(); } mDrawing = strokes; sreader.endObject(); }
private ArrayList<Category> parseCategoriesList(JsonReader reader) throws IOException { ArrayList<Category> result = new ArrayList<>(); String name = reader.nextName(); reader.beginArray(); while (reader.hasNext()) { Category category = parseCategory(reader); if (category != null) { result.add(category); } } reader.endArray(); return result; }
protected final void addHtmlPageUrl(JsonReader jsonreader, ContentValues contentvalues) throws IOException { jsonreader.beginArray(); ContentValues contentvalues1 = new ContentValues(); do { if (!jsonreader.hasNext()) break; contentvalues1.clear(); parseObject(jsonreader, sLinkFieldMap, contentvalues1); String s = contentvalues1.getAsString("rel"); String s1 = contentvalues1.getAsString("type"); if (!Utils.equals(s, "alternate") || !Utils.equals(s1, "text/html")) continue; contentvalues.put("html_page_url", contentvalues1.getAsString("href")); for (; jsonreader.hasNext(); jsonreader.skipValue()) ; break; } while (true); jsonreader.endArray(); }
private void readGeometry(JsonReader reader) throws IOException { String s; reader.beginObject(); while (reader.hasNext()) { s = reader.nextName(); if (s.equals("coordinates")) { reader.beginArray(); location = new Location("http://earthquake.usgs.gov/"); location.setLongitude(reader.nextDouble()); location.setLatitude(reader.nextDouble()); location.setAltitude(-reader.nextDouble()); reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static final List<Place> GetPlaces(String source) throws IOException { ArrayList<Place> places = new ArrayList<Place>(); JsonReader reader = null; try { reader = new JsonReader(new StringReader(source)); reader.beginArray(); while (reader.hasNext()) { String Code = null; String Name = null; String HubCode = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("Code")) { Code = reader.nextString(); } else if (name.equals("Name")) { Name = reader.nextString(); } else if (name.equals("HubCode")) { HubCode = reader.nextString(); } else { reader.skipValue(); } } reader.endObject(); Place place = new Place(); place.Code = Code; place.Name = Name; place.HubCode = HubCode; places.add(place); } reader.endArray(); } finally { if (reader != null) reader.close(); } return places; }
public Button parseButton(JsonReader jsonReader) { Button button = new Button(); try { jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals(JSON_KEY_BUT_TARGET)) { button.setTarget(jsonReader.nextString()); } else if (name.equals(JSON_KEY_BUT_TITLE)) { button.setTitle(jsonReader.nextString()); } else { jsonReader.skipValue(); } } jsonReader.endObject(); } catch (IOException e) { } catch (Exception e) { try { jsonReader.beginArray(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if (name.equals(JSON_KEY_BUT_TARGET)) { button.setTarget(jsonReader.nextString()); } else if (name.equals(JSON_KEY_BUT_TITLE)) { button.setTitle(jsonReader.nextString()); } else { jsonReader.skipValue(); } } jsonReader.endObject(); jsonReader.endArray(); } catch (IOException e2) { } } return button; }
public static SatsClass createUsingJsonStream(Realm realm, JsonReader reader) throws IOException { SatsClass obj = realm.createObject(SatsClass.class); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("id") && reader.peek() != JsonToken.NULL) { obj.setId((String) reader.nextString()); } else if (name.equals("centerFilterId") && reader.peek() != JsonToken.NULL) { obj.setCenterFilterId((String) reader.nextString()); } else if (name.equals("classTypeId") && reader.peek() != JsonToken.NULL) { obj.setClassTypeId((String) reader.nextString()); } else if (name.equals("durationInMinutes") && reader.peek() != JsonToken.NULL) { obj.setDurationInMinutes((int) reader.nextInt()); } else if (name.equals("instructorId") && reader.peek() != JsonToken.NULL) { obj.setInstructorId((String) reader.nextString()); } else if (name.equals("name") && reader.peek() != JsonToken.NULL) { obj.setName((String) reader.nextString()); } else if (name.equals("startTime") && reader.peek() != JsonToken.NULL) { obj.setStartTime((String) reader.nextString()); } else if (name.equals("bookedPersonsCount") && reader.peek() != JsonToken.NULL) { obj.setBookedPersonsCount((int) reader.nextInt()); } else if (name.equals("maxPersonsCount") && reader.peek() != JsonToken.NULL) { obj.setMaxPersonsCount((int) reader.nextInt()); } else if (name.equals("regionId") && reader.peek() != JsonToken.NULL) { obj.setRegionId((String) reader.nextString()); } else if (name.equals("waitingListCount") && reader.peek() != JsonToken.NULL) { obj.setWaitingListCount((int) reader.nextInt()); } else if (name.equals("classCategoryIds") && reader.peek() != JsonToken.NULL) { reader.beginArray(); while (reader.hasNext()) { se.greatbrain.sats.data.model.ClassCategoryIds item = ClassCategoryIdsRealmProxy.createUsingJsonStream(realm, reader); obj.getClassCategoryIds().add(item); } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); return obj; }
public static final List<NomenclatureItem> GetNomenclatureItems(String source) throws IOException { ArrayList<NomenclatureItem> items = new ArrayList<NomenclatureItem>(); JsonReader reader = null; try { reader = new JsonReader(new StringReader(source)); reader.beginArray(); while (reader.hasNext()) { String Code = null; String Name = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("Code")) { Code = reader.nextString(); } else if (name.equals("Name")) { Name = reader.nextString(); } else { reader.skipValue(); } } reader.endObject(); NomenclatureItem item = new NomenclatureItem(); item.Code = Code; item.Name = Name; items.add(item); } reader.endArray(); } finally { if (reader != null) reader.close(); } return items; }
@Override public void deSerializeRepresentation(JsonReader sreader) throws IOException { sreader.beginObject(); Vector<Band> points = new Vector<Band>(); while (sreader.hasNext()) { String name = sreader.nextName(); if (name.startsWith(LINE_NAME)) { int pointNo = Integer.parseInt(name.substring(LINE_NAME.length())); sreader.beginArray(); Band p = new Band(); p.mask = false; sreader.hasNext(); p.xPos1 = sreader.nextInt(); sreader.hasNext(); p.yPos1 = sreader.nextInt(); sreader.hasNext(); p.xPos2 = sreader.nextInt(); sreader.hasNext(); p.yPos2 = sreader.nextInt(); sreader.hasNext(); p.brightness = sreader.nextInt(); sreader.hasNext(); p.contrast = sreader.nextInt(); sreader.hasNext(); p.saturation = sreader.nextInt(); sreader.hasNext(); sreader.endArray(); points.add(p); } else { sreader.skipValue(); } } mBands = points; trimVector(); mCurrentBand = mBands.get(0); sreader.endObject(); }