Java Code Examples for android.util.JsonReader#nextInt()

The following examples show how to use android.util.JsonReader#nextInt() . 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: GalleryData.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
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 2
Source File: BundleDeltaClient.java    From react-native-GPay with MIT License 6 votes vote down vote up
private static int patchDelta(JsonReader jsonReader, LinkedHashMap<Number, byte[]> map)
  throws IOException {
  jsonReader.beginArray();

  int numModules = 0;
  while (jsonReader.hasNext()) {
    jsonReader.beginArray();

    int moduleId = jsonReader.nextInt();

    if (jsonReader.peek() == JsonToken.NULL) {
      jsonReader.skipValue();
      map.remove(moduleId);
    } else {
      map.put(moduleId, jsonReader.nextString().getBytes());
    }

    jsonReader.endArray();
    numModules++;
  }

  jsonReader.endArray();

  return numModules;
}
 
Example 3
Source File: User.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public User(JsonReader reader) throws IOException {
    reader.beginObject();
    while(reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "id":id=reader.nextInt();break;
            case "post_date":username=reader.nextString();break;
            case "avatar_url":avatarUrl=reader.nextString();break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example 4
Source File: Comment.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Comment(JsonReader reader) throws IOException {
    reader.beginObject();
    while(reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "id":id=reader.nextInt();break;
            case "post_date":postDate=new Date(reader.nextLong()*1000);break;
            case "body":body=reader.nextString();break;
            case "poster":poster=new User(reader);break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example 5
Source File: Tag.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Tag(JsonReader jr) throws IOException {
    jr.beginObject();
    while(jr.peek()!= JsonToken.END_OBJECT){
        switch (jr.nextName()){
            case "count":count=jr.nextInt();break;
            case "type":type=TagType.typeByName(jr.nextString());break;
            case "id":id=jr.nextInt();break;
            case "name":name=jr.nextString();break;
            case "url": LogUtility.d("Tag URL: "+jr.nextString());break;
            default:jr.skipValue();break;
        }
    }
    jr.endObject();
}
 
Example 6
Source File: ScrapeTags.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
private Tag readTag(JsonReader reader) throws IOException {
    reader.beginArray();
    int id=reader.nextInt();
    String name=reader.nextString();
    int count=reader.nextInt();
    TagType type=TagType.values[reader.nextInt()];
    reader.endArray();
    return new Tag(name,count,id,type,TagStatus.DEFAULT);
}
 
Example 7
Source File: JSDebuggerWebSocketClient.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onMessage(WebSocket webSocket, String text) {
  Integer replyID = null;

  try {
    JsonReader reader = new JsonReader(new StringReader(text));
    String result = null;
    reader.beginObject();
    while (reader.hasNext()) {
      String field = reader.nextName();

      if (JsonToken.NULL == reader.peek()) {
        reader.skipValue();
        continue;
      }

      if ("replyID".equals(field)) {
        replyID = reader.nextInt();
      } else if ("result".equals(field)) {
        result = reader.nextString();
      } else if ("error".equals(field)) {
        String error = reader.nextString();
        abort(error, new JavascriptException(error));
      }
    }
    if (replyID != null) {
      triggerRequestSuccess(replyID, result);
    }
  } catch (IOException e) {
    if (replyID != null) {
      triggerRequestFailure(replyID, e);
    } else {
      abort("Parsing response message from websocket failed", e);
    }
  }
}
 
Example 8
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 9
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<RatingAspect> readAspectsArray(JsonReader reader) throws IOException {
    List<RatingAspect> aspects = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        int rating = -1;
        String type = null;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "rating":
                    rating = reader.nextInt();
                    break;
                case "type":
                    type = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        aspects.add(new RatingAspect(rating, type));
    }
    reader.endArray();
    return aspects;
}
 
Example 10
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<MatchedSubstring> readMatchedSubstringsArray(JsonReader reader) throws IOException {
    List<MatchedSubstring> matchedSubstrings = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        int length = -1;
        int offset = -1;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "length":
                    length = reader.nextInt();
                    break;
                case "offset":
                    offset = reader.nextInt();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        matchedSubstrings.add(new MatchedSubstring(length, offset));
    }
    reader.endArray();
    return matchedSubstrings;
}
 
Example 11
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 5 votes vote down vote up
List<DescriptionTerm> readDescriptionTermsArray(JsonReader reader) throws IOException {
    List<DescriptionTerm> terms = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        int offset = -1;
        String value = null;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "offset":
                    offset = reader.nextInt();
                    break;
                case "value":
                    value = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        terms.add(new DescriptionTerm(offset, value));
    }
    reader.endArray();
    return terms;
}
 
Example 12
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void readNGWDate(Feature feature, JsonReader reader, String fieldName)
        throws IOException
{
    reader.beginObject();
    int nYear = 1900;
    int nMonth = 1;
    int nDay = 1;
    int nHour = 0;
    int nMinute = 0;
    int nSecond = 0;
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(NGWUtil.NGWKEY_YEAR)) {
            nYear = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_MONTH)) {
            nMonth = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_DAY)) {
            nDay = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_HOUR)) {
            nHour = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_MINUTE)) {
            nMinute = reader.nextInt();
        } else if (name.equals(NGWUtil.NGWKEY_SECOND)) {
            nSecond = reader.nextInt();
        } else {
            reader.skipValue();
        }
    }

    TimeZone timeZone = TimeZone.getDefault();
    timeZone.setRawOffset(0); // set to UTC
    Calendar calendar = new GregorianCalendar(timeZone);
    calendar.set(nYear, nMonth - 1, nDay, nHour, nMinute, nSecond);
    calendar.set(Calendar.MILLISECOND, 0); // we must to reset millis
    feature.setFieldValue(fieldName, calendar.getTimeInMillis());

    reader.endObject();
}
 
Example 13
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 4 votes vote down vote up
List<PlaceReview> readReviewsArray(JsonReader reader) throws IOException {
    List<PlaceReview> reviews = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        List<RatingAspect> aspects = null;
        String authorName = null;
        String authorUrl = null;
        String language = null;
        int rating = -1;
        String text = null;
        long time = -1L;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "aspects":
                    aspects = readAspectsArray(reader);
                    break;
                case "author_name":
                    authorName = reader.nextString();
                    break;
                case "author_url":
                    authorUrl = reader.nextString();
                    break;
                case "language":
                    language = reader.nextString();
                    break;
                case "rating":
                    rating = reader.nextInt();
                    break;
                case "text":
                    text = reader.nextString();
                    break;
                case "time":
                    time = reader.nextLong();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        reviews.add(new PlaceReview(aspects, authorName, authorUrl, language, rating, text, time));
    }
    reader.endArray();
    return reviews;
}