當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonReader.peek方法代碼示例

本文整理匯總了Java中android.util.JsonReader.peek方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonReader.peek方法的具體用法?Java JsonReader.peek怎麽用?Java JsonReader.peek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.util.JsonReader的用法示例。


在下文中一共展示了JsonReader.peek方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parse

import android.util.JsonReader; //導入方法依賴的package包/類
@Override public Integer parse(JsonReader reader, float scale) throws IOException {
  boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY;
  if (isArray) {
    reader.beginArray();
  }
  double r = reader.nextDouble();
  double g = reader.nextDouble();
  double b = reader.nextDouble();
  double a = reader.nextDouble();
  if (isArray) {
    reader.endArray();
  }

  if (r <= 1 && g <= 1 && b <= 1 && a <= 1) {
    r *= 255;
    g *= 255;
    b *= 255;
    a *= 255;
  }

  return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
開發者ID:airbnb,項目名稱:lottie-android,代碼行數:23,代碼來源:ColorParser.java

示例2: parse

import android.util.JsonReader; //導入方法依賴的package包/類
@Override public PointF parse(JsonReader reader, float scale) throws IOException {
  JsonToken token = reader.peek();
  if (token == JsonToken.BEGIN_ARRAY) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.BEGIN_OBJECT) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.NUMBER) {
    // This is the case where the static value for a property is an array of numbers.
    // We begin the array to see if we have an array of keyframes but it's just an array
    // of static numbers instead.
    PointF point = new PointF((float) reader.nextDouble() * scale, (float) reader.nextDouble() * scale);
    while (reader.hasNext()) {
      reader.skipValue();
    }
    return point;
  } else {
    throw new IllegalArgumentException("Cannot convert json to point. Next token is " + token);
  }
}
 
開發者ID:airbnb,項目名稱:lottie-android,代碼行數:20,代碼來源:PointFParser.java

示例3: valueFromObject

import android.util.JsonReader; //導入方法依賴的package包/類
static float valueFromObject(JsonReader reader) throws IOException {
  JsonToken token = reader.peek();
  switch (token) {
    case NUMBER:
      return (float) reader.nextDouble();
    case BEGIN_ARRAY:
      reader.beginArray();
      float val = (float) reader.nextDouble();
      while (reader.hasNext()) {
        reader.skipValue();
      }
      reader.endArray();
      return val;
    default:
      throw new IllegalArgumentException("Unknown value for token of type " + token);
  }
}
 
開發者ID:airbnb,項目名稱:lottie-android,代碼行數:18,代碼來源:JsonUtils.java

示例4: readValue

import android.util.JsonReader; //導入方法依賴的package包/類
/** Reads the next value in the {@link JsonReader}. */
private static Object readValue(JsonReader reader) throws IOException {
  JsonToken token = reader.peek();
  switch (token) {
    case BEGIN_OBJECT:
      return readerToMap(reader);
    case BEGIN_ARRAY:
      return readerToList(reader);
    case BOOLEAN:
      return reader.nextBoolean();
    case NULL:
      reader.nextNull(); // consume the null token
      return null;
    case NUMBER:
      return reader.nextDouble();
    case STRING:
      return reader.nextString();
    default:
      throw new IllegalStateException("Invalid token " + token);
  }
}
 
開發者ID:f2prateek,項目名稱:segment-android,代碼行數:22,代碼來源:JsonUtils.java

示例5: deserializeStringCollection

import android.util.JsonReader; //導入方法依賴的package包/類
/**
 * A generic deserializer for string collections.
 *
 * @param serialized      JSON representation of a string collection.
 * @param collectionClass Concrete, instantiatable collection class, e.g. {@code ArrayList.class}.
 * @param <C>             A concrete collection class, e.g. {@code ArrayList<String>}.
 * @return A collection instance retrieved from {@code serialized}.
 */
@NonNull
public static <C extends Collection<String>> C deserializeStringCollection(@NonNull String serialized,
        @NonNull Class<?> collectionClass) {
    C collection = createCollection(collectionClass);

    StringReader reader = new StringReader(serialized);
    JsonReader jsonReader = new JsonReader(reader);

    try {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            if (jsonReader.peek() == JsonToken.NULL) {
                jsonReader.nextNull();
                collection.add(null);
            } else {
                collection.add(jsonReader.nextString());
            }
        }
        jsonReader.endArray();
        jsonReader.close();
        return collection;
    } catch (IOException e) {
        return collection;
    }
}
 
開發者ID:maskarade,項目名稱:Android-Orma,代碼行數:34,代碼來源:BuiltInSerializers.java

示例6: insertJournal

import android.util.JsonReader; //導入方法依賴的package包/類
private void insertJournal(JsonReader jsonReader, Journal journal) throws IOException {
    jsonReader.beginObject();
    while (jsonReader.hasNext()) {
        String key = jsonReader.nextName();
        if(jsonReader.peek() == JsonToken.NULL) continue;
        if (key.equals(KEY_ID)) journal.setId(jsonReader.nextLong());
        else if (key.equals(KEY_DATE)) journal.setDate(jsonReader.nextLong());
        else if (key.equals(KEY_NOTE)) journal.setNote(jsonReader.nextString());
        else if (key.equals(KEY_AMOUNT)) journal.setAmount(jsonReader.nextDouble());
        else if (key.equals(KEY_CREATED_DATE)) journal.setCreatedDate(jsonReader.nextLong());
        else if (key.equals(KEY_TYPE)) journal.setType(Journal.Type.valueOf(jsonReader.nextString()));
        else if (key.equals(KEY_ATTACHMENTS)) {
            //this logic assumes that key_attachments comes at the end
            long newId = mServices.addJournal(journal);
            insertAttachmentsIntoDB(jsonReader, newId);
        }
        else jsonReader.skipValue();
    }
    jsonReader.endObject();
}
 
開發者ID:ndhunju,項目名稱:dailyJournal,代碼行數:21,代碼來源:JsonConverterStream.java

示例7: insertAttachment

import android.util.JsonReader; //導入方法依賴的package包/類
private void insertAttachment(JsonReader jsonReader, Attachment attachment) throws IOException {
    if(jsonReader.peek() == JsonToken.NAME) {
        jsonReader.beginObject();
        while (jsonReader.hasNext()) {
            String key = jsonReader.nextName();
            if (jsonReader.peek() == JsonToken.NULL) continue;
            if (key.equals(KEY_ID)) attachment.setId(jsonReader.nextLong());
            else if (key.equals(KEY_PATH)) attachment.setPath(jsonReader.nextString());
            else jsonReader.skipValue();
        }
        mServices.addAttachment(attachment);
        jsonReader.endObject();
    }else{
        //for old json format
        while (jsonReader.hasNext()) {
            if (jsonReader.peek() == JsonToken.NULL) continue;
            else attachment.setPath(jsonReader.nextString());
        }
        mServices.addAttachment(attachment);
    }
}
 
開發者ID:ndhunju,項目名稱:dailyJournal,代碼行數:22,代碼來源:JsonConverterStream.java

示例8: inflate

import android.util.JsonReader; //導入方法依賴的package包/類
/***
 * This method called in the background, here
 * need to parse given {@code json}
 *
 * @param reader Widget configuration
 */
protected void inflate(ConfigurationWidget widget, JsonReader reader) throws IOException {
    Bundle options = new Bundle();
    Bundle configs = widget.getConfigurations();
    JsonToken token = reader.peek();
    if(token == JsonToken.BEGIN_OBJECT){
        appendViewInLayout(createView(this, configs, options, reader));
    }else if (token == JsonToken.BEGIN_ARRAY){
        reader.beginArray();
        while(reader.peek() != JsonToken.END_ARRAY){
            appendViewInLayout(createView(this, configs, options, reader));
            options.clear(); // recycle configurations
        }
        reader.endArray();
    }else{
        throw new RuntimeException("Unsupported token exception: " + reader.toString());
    }
    options.clear();
}
 
開發者ID:ozodrukh,項目名稱:Green,代碼行數:25,代碼來源:ConfigCard.java

示例9: handleSystemOptions

import android.util.JsonReader; //導入方法依賴的package包/類
private static boolean handleSystemOptions(Bundle options, String key, JsonReader reader){
    try {
        if (key.equals("entities")) {
            reader.beginObject();
            ArrayList<String> entities = new ArrayList<>();
            while(reader.peek() != JsonToken.END_OBJECT){
                reader.skipValue(); //skip name
                entities.add(reader.nextString());
            }
            reader.endObject();
            options.putStringArrayList(key, entities);
            return true;
        }
    }catch (IOException e){
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:ozodrukh,項目名稱:Green,代碼行數:19,代碼來源:ConfigCard.java

示例10: createUsingJsonStream

import android.util.JsonReader; //導入方法依賴的package包/類
@SuppressWarnings("cast")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static some.test.Simple createUsingJsonStream(Realm realm, JsonReader reader)
        throws IOException {
    final some.test.Simple obj = new some.test.Simple();
    final SimpleRealmProxyInterface objProxy = (SimpleRealmProxyInterface) obj;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (false) {
        } else if (name.equals("name")) {
            if (reader.peek() != JsonToken.NULL) {
                objProxy.realmSet$name((String) reader.nextString());
            } else {
                reader.skipValue();
                objProxy.realmSet$name(null);
            }
        } else if (name.equals("age")) {
            if (reader.peek() != JsonToken.NULL) {
                objProxy.realmSet$age((int) reader.nextInt());
            } else {
                reader.skipValue();
                throw new IllegalArgumentException("Trying to set non-nullable field 'age' to null.");
            }
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return realm.copyToRealm(obj);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:SimpleRealmProxy.java

示例11: readImageUri

import android.util.JsonReader; //導入方法依賴的package包/類
private void readImageUri(JsonReader reader) throws IOException {
    reader.nextName();
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
        mImageUri = null;
    } else
        mImageUri = reader.nextString();
}
 
開發者ID:olgamiller,項目名稱:SSTVEncoder2,代碼行數:9,代碼來源:Settings.java

示例12: parse

import android.util.JsonReader; //導入方法依賴的package包/類
PodcastLayoutContent parse(Reader reader, URI uri) throws IOException {
    JsonReader parser = new JsonReader(reader);

    long id = 0;
    String name = null;

    long nextPage = 0;

    Records records = null;

    parser.beginObject();
    while (parser.hasNext()) {
        String prop = parser.nextName();
        if (ID_PROPERTY.equals(prop)) {
            id = parser.nextLong();
        } else if (TITLE_PROPERTY.equals(prop)) {
            name = StringUtils.nonEmpty(parser.nextString());
        } else if (NEXT_PAGE_PROPERTY.equals(prop)) {
            if (parser.peek() == JsonToken.NUMBER) {
                nextPage = parser.nextLong();
            } else {
                parser.skipValue();
            }
        } else if (RECORDS_PROPERTY.equals(prop)) {
            records = parseRecords(parser, uri);
        } else {
            parser.skipValue();
        }
    }
    parser.endObject();

    Podcast podcast = null;
    if (id != 0 && name != null) {
        podcast = new Podcast(id, name);
    }
    return new PodcastLayoutContent(podcast, records == null ? new Records() : records, nextPage);
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:38,代碼來源:PodcastJsonParser.java

示例13: extractSite

import android.util.JsonReader; //導入方法依賴的package包/類
private static void extractSite(final JsonReader reader, final UrlListCallback callback) throws IOException {
    reader.beginObject();

    final String siteOwner = reader.nextName();
    {
        reader.beginObject();

        while (reader.hasNext()) {
            // We can get the site name using reader.nextName() here:
            reader.skipValue();

            JsonToken nextToken = reader.peek();

            if (nextToken.name().equals("STRING")) {
                // Sometimes there's a "dnt" entry, with unspecified purpose.
                reader.skipValue();
            } else {
                reader.beginArray();

                while (reader.hasNext()) {
                    final String blockURL = reader.nextString();
                    callback.put(blockURL, siteOwner);
                }

                reader.endArray();
            }
        }

        reader.endObject();
    }

    reader.endObject();
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:34,代碼來源:BlocklistProcessor.java

示例14: hasNextSkipNull

import android.util.JsonReader; //導入方法依賴的package包/類
protected static boolean hasNextSkipNull(JsonReader reader) throws IOException {
    while (reader.hasNext()) {
        if (reader.peek() == JsonToken.NULL) {
            reader.skipValue();
        } else {
            return true;
        }
    }
    return false;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:11,代碼來源:JSONStreamParser.java

示例15: getNextNotNullName

import android.util.JsonReader; //導入方法依賴的package包/類
protected static final String getNextNotNullName(JsonReader reader) throws IOException {
    while (reader.hasNext()) {
        String name = reader.nextName();
        JsonToken jsonToken = reader.peek();
        if (jsonToken != JsonToken.NULL) {
            return name;
        }
        reader.skipValue();
    }
    return null;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:12,代碼來源:JSONStreamParser.java


注:本文中的android.util.JsonReader.peek方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。