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


Java JsonReader.hasNext方法代碼示例

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


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

示例1: createAllFromJson

import android.util.JsonReader; //導入方法依賴的package包/類
/**
 * Creates a Realm object for each object in a JSON array. This must be done within a transaction.
 * JSON properties with unknown properties will be ignored. If a {@link RealmObject} field is not present in the
 * JSON object the {@link RealmObject} field will be set to the default value for that type.
 * <p>
 * This API is only available in API level 11 or later.
 *
 * <p>
 * This method currently does not support value list field.
 *
 * @param clazz type of Realm objects created.
 * @param inputStream the JSON array as a InputStream. All objects in the array must be of the specified class.
 * @throws RealmException if mapping from JSON fails.
 * @throws IllegalArgumentException if the JSON object doesn't have a primary key property but the corresponding
 * {@link RealmObjectSchema} has a {@link io.realm.annotations.PrimaryKey} defined.
 * @throws IOException if something was wrong with the input stream.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public <E extends RealmModel> void createAllFromJson(Class<E> clazz, InputStream inputStream) throws IOException {
    //noinspection ConstantConditions
    if (clazz == null || inputStream == null) {
        return;
    }
    checkIfValid();

    JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
    try {
        reader.beginArray();
        while (reader.hasNext()) {
            configuration.getSchemaMediator().createUsingJsonStream(clazz, this, reader);
        }
        reader.endArray();
    } finally {
        reader.close();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:Realm.java

示例2: Port

import android.util.JsonReader; //導入方法依賴的package包/類
public Port(JsonReader jsonReader) throws IOException {
    jsonReader.beginObject();
    String id = null;
    String name = null;
    while (jsonReader.hasNext()) {
        String key = jsonReader.nextName();
        if (id == null && ID.equals(key)) {
            id = jsonReader.nextString();
        } else if (name == null && NAME.equals(key)) {
            name = jsonReader.nextString();
        } else {
            jsonReader.skipValue();
        }
    }
    jsonReader.endObject();
    this.id = id;
    this.name = name;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:19,代碼來源:Port.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: findCandidates

import android.util.JsonReader; //導入方法依賴的package包/類
private List<Politician> findCandidates(List<String> cpfList, JsonReader reader) throws IOException {
    reader.beginArray();

    List<Politician> candidates = new ArrayList<>();
    while (reader.hasNext()) {
        reader.beginObject();
        String polCpf = reader.nextName();
        int index = cpfList.indexOf(polCpf);
        if (index != -1) {
            Politician pol = new Politician(polCpf);
            readJsonObject(reader, pol);
            candidates.add(pol);
        }
        else {
            reader.skipValue();
        }
        reader.endObject();
    }

    reader.endArray();
    return candidates;
}
 
開發者ID:TekkLabs,項目名稱:memoria-politica,代碼行數:23,代碼來源:CandidateDao.java

示例5: parse

import android.util.JsonReader; //導入方法依賴的package包/類
static MergePaths parse(JsonReader reader) throws IOException {
  String name = null;
  MergePaths.MergePathsMode mode = null;

  while (reader.hasNext()) {
    switch (reader.nextName()) {
      case "nm":
        name = reader.nextString();
        break;
      case "mm":
        mode =  MergePaths.MergePathsMode.forId(reader.nextInt());
        break;
      default:
        reader.skipValue();
    }
  }

  return new MergePaths(name, mode);
}
 
開發者ID:airbnb,項目名稱:lottie-android,代碼行數:20,代碼來源:MergePathsParser.java

示例6: parseFonts

import android.util.JsonReader; //導入方法依賴的package包/類
private static void parseFonts(JsonReader reader, Map<String, Font> fonts) throws IOException {

    reader.beginObject();
    while (reader.hasNext()) {
      switch (reader.nextName()) {
        case "list":
          reader.beginArray();
          while (reader.hasNext()) {
            Font font = FontParser.parse(reader);
            fonts.put(font.getName(), font);
          }
          reader.endArray();
          break;
        default:
          reader.skipValue();
      }
    }
    reader.endObject();
  }
 
開發者ID:airbnb,項目名稱:lottie-android,代碼行數:20,代碼來源:LottieCompositionParser.java

示例7: 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

示例8: readErrorMessage

import android.util.JsonReader; //導入方法依賴的package包/類
private RegistrationApiErrorResponse readErrorMessage(JsonReader reader)
        throws IOException {
    String message = "";
    String errorDetail = "";
    List<ResponseError> modelStateErrors = null;

    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("Message")) {
            message = reader.nextString();
        } else if (name.equals("ErrorMessage")) {
            errorDetail = reader.nextString();
        } else if (name.equals("ModelState")) {
            modelStateErrors = readModelState(reader);
        }
    }
    reader.endObject();

    return new RegistrationApiErrorResponse(message, errorDetail, modelStateErrors);
}
 
開發者ID:SocketMobile,項目名稱:samples-android,代碼行數:22,代碼來源:RegistrationApiErrorResponse.java

示例9: deSerializeRepresentation

import android.util.JsonReader; //導入方法依賴的package包/類
@Override
public void deSerializeRepresentation(JsonReader reader) throws IOException {
    boolean unset = true;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (SERIALIZATION_ROTATE_VALUE.equals(name)) {
            Rotation r = Rotation.fromValue(reader.nextInt());
            if (r != null) {
                setRotation(r);
                unset = false;
            }
        } else {
            reader.skipValue();
        }
    }
    if (unset) {
        Log.w(TAG, "WARNING: bad value when deserializing " + SERIALIZATION_NAME);
    }
    reader.endObject();
}
 
開發者ID:asm-products,項目名稱:nexus-gallery,代碼行數:22,代碼來源:FilterRotateRepresentation.java

示例10: deSerializeRepresentation

import android.util.JsonReader; //導入方法依賴的package包/類
@Override
public void deSerializeRepresentation(JsonReader reader) throws IOException {
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (BOUNDS[0].equals(name)) {
            mCrop.left = (float) reader.nextDouble();
        } else if (BOUNDS[1].equals(name)) {
            mCrop.top = (float) reader.nextDouble();
        } else if (BOUNDS[2].equals(name)) {
            mCrop.right = (float) reader.nextDouble();
        } else if (BOUNDS[3].equals(name)) {
            mCrop.bottom = (float) reader.nextDouble();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
}
 
開發者ID:asm-products,項目名稱:nexus-gallery,代碼行數:20,代碼來源:FilterCropRepresentation.java

示例11: jsonStrToList

import android.util.JsonReader; //導入方法依賴的package包/類
public static List<Object> jsonStrToList(final String s) {
    final ArrayList<Object> list = new ArrayList<>();
    final JsonReader reader = new JsonReader(new StringReader(s));
    try {
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginObject();
            while (reader.hasNext()) {
                final String name = reader.nextName();
                if (name.equals(INTEGER_CLASS_NAME)) {
                    list.add(reader.nextInt());
                } else if (name.equals(STRING_CLASS_NAME)) {
                    list.add(reader.nextString());
                } else {
                    Log.w(TAG, "Invalid name: " + name);
                    reader.skipValue();
                }
            }
            reader.endObject();
        }
        reader.endArray();
        return list;
    } catch (final IOException e) {
    } finally {
        close(reader);
    }
    return Collections.<Object>emptyList();
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:29,代碼來源:JsonUtils.java

示例12: readSampleGroup

import android.util.JsonReader; //導入方法依賴的package包/類
private void readSampleGroup(JsonReader reader, List<SampleGroup> groups) throws IOException {
  String groupName = "";
  ArrayList<Sample> samples = new ArrayList<>();

  reader.beginObject();
  while (reader.hasNext()) {
    String name = reader.nextName();
    switch (name) {
      case "name":
        groupName = reader.nextString();
        break;
      case "samples":
        reader.beginArray();
        while (reader.hasNext()) {
          samples.add(readEntry(reader, false));
        }
        reader.endArray();
        break;
      case "offline_samples":
        reader.beginArray();
        while (reader.hasNext()){
          samples.add(readOfflineEntry(reader));
        }
        reader.endArray();
        break;
      case "_comment":
        reader.nextString(); // Ignore.
        break;
      default:
        throw new ParserException("Unsupported name: " + name);
    }
  }
  reader.endObject();

  SampleGroup group = getGroup(groupName, groups);
  group.samples.addAll(samples);
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:38,代碼來源:SampleChooserActivity.java

示例13: readPlace

import android.util.JsonReader; //導入方法依賴的package包/類
Address readPlace(JsonReader reader) throws IOException {
    String text = null;
    String streetLine = null;
    String city = null;
    String state = null;
    reader.beginObject();
    while (reader.hasNext()) {
        switch (reader.nextName()) {
            case "text":
                text = reader.nextString();
                break;
            case "street_line":
                streetLine = reader.nextString();
                break;
            case "city":
                city = reader.nextString();
                break;
            case "state":
                state = reader.nextString();
                break;
            default:
                reader.skipValue();
                break;
        }
    }
    reader.endObject();
    return new Address(text, streetLine, city, state);
}
 
開發者ID:RacZo,項目名稱:Smarty-Streets-AutoCompleteTextView,代碼行數:29,代碼來源:AndroidSmartyStreetsApiJsonParser.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: parseMetadata

import android.util.JsonReader; //導入方法依賴的package包/類
/**
 * Parses metadata in the JSON format.
 * @param input a stream reader expected to contain JSON formatted metadata.
 * @return dictionary metadata, as an array of WordListMetadata objects.
 * @throws IOException if the underlying reader throws IOException during reading.
 * @throws BadFormatException if the data was not in the expected format.
 */
public static List<WordListMetadata> parseMetadata(final InputStreamReader input)
        throws IOException, BadFormatException {
    JsonReader reader = new JsonReader(input);
    final ArrayList<WordListMetadata> readInfo = new ArrayList<>();
    reader.beginArray();
    while (reader.hasNext()) {
        final WordListMetadata thisMetadata = parseOneWordList(reader);
        if (!TextUtils.isEmpty(thisMetadata.mLocale))
            readInfo.add(thisMetadata);
    }
    return Collections.unmodifiableList(readInfo);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:20,代碼來源:MetadataParser.java


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