Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  /**
   * 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;
    }
  }
Exemplo n.º 3
0
  @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 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();
    }
  }
Exemplo n.º 5
0
 private void readFeaturesArray(JsonReader reader) throws IOException {
   reader.beginArray();
   while (reader.hasNext()) {
     readErthquake(reader);
   }
   reader.endArray();
 }
Exemplo n.º 6
0
  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;
  }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
0
 /** Parse metric array */
 void parseArray() throws IOException {
   _reader.beginArray();
   while (_reader.hasNext()) {
     parseBody();
   }
   _reader.endArray();
 }
Exemplo n.º 9
0
 private void readArticlesArray(List<SnippetListItem> listSnippetItems, JsonReader reader)
     throws IOException {
   reader.beginArray();
   while (reader.hasNext()) {
     listSnippetItems.add(readArticleDetails(reader));
   }
   reader.endArray();
 }
Exemplo n.º 10
0
  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;
  }
Exemplo n.º 11
0
  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;
  }
Exemplo n.º 12
0
  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;
  }
Exemplo n.º 13
0
    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;
  }
Exemplo n.º 15
0
  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;
  }
Exemplo n.º 16
0
 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;
 }
Exemplo n.º 17
0
  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 void readMessagesArray(JsonReader reader) throws IOException {

    reader.beginArray();
    while (reader.hasNext()) {
      readMessage(reader);

      key++;

      addToList(key, marker, polygon);
    } // while
    reader.endArray();
  }
Exemplo n.º 19
0
 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();
 }
Exemplo n.º 20
0
  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;
  }
Exemplo n.º 21
0
  @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();
  }
Exemplo n.º 22
0
  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;
  }
Exemplo n.º 23
0
 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();
 }
Exemplo n.º 24
0
 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;
  }
Exemplo n.º 26
0
  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;
  }
Exemplo n.º 27
0
 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();
  }
Exemplo n.º 30
0
  private List<Post> loadThread(JsonReader reader) throws Exception {
    ArrayList<Post> list = new ArrayList<>();

    reader.beginObject();
    // Page object
    while (reader.hasNext()) {
      String key = reader.nextName();
      if (key.equals("posts")) {
        reader.beginArray();
        // Thread array
        while (reader.hasNext()) {
          // Thread object
          list.add(readPostObject(reader));
        }
        reader.endArray();
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();

    return list;
  }