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


Java JsonReader.hasNext方法代碼示例

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


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

示例1: processDataBody

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
/**
 * Processes a conference data body and calls the appropriate data type handlers
 * to process each of the objects represented therein.
 *
 * @param dataBody The body of data to process
 * @throws IOException If there is an error parsing the data.
 */
private void processDataBody(String dataBody) throws IOException {
    JsonReader reader = new JsonReader(new StringReader(dataBody));
    JsonParser parser = new JsonParser();
    try {
        reader.setLenient(true); // To err is human

        // the whole file is a single JSON object
        reader.beginObject();

        while (reader.hasNext()) {
            // the key is "rooms", "speakers", "tracks", etc.
            String key = reader.nextName();
            if (mHandlerForKey.containsKey(key)) {
                // pass the value to the corresponding handler
                mHandlerForKey.get(key).process(parser.parse(reader));
            } else {
                LOGW(TAG, "Skipping unknown key in conference data json: " + key);
                reader.skipValue();
            }
        }
        reader.endObject();
    } finally {
        reader.close();
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:33,代碼來源:ConferenceDataHandler.java

示例2: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
public T read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
    }
    T instance = this.constructor.construct();
    try {
        in.beginObject();
        while (in.hasNext()) {
            BoundField field = (BoundField) this.boundFields.get(in.nextName());
            if (field == null || !field.deserialized) {
                in.skipValue();
            } else {
                field.read(in, instance);
            }
        }
        in.endObject();
        return instance;
    } catch (Throwable e) {
        throw new JsonSyntaxException(e);
    } catch (IllegalAccessException e2) {
        throw new AssertionError(e2);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:ReflectiveTypeAdapterFactory.java

示例3: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public void read(JsonReader in, GsonProperty property, Object t) throws IOException {
    final Class<?> simpleType = property.getType();

    List list = new ArrayList();
    in.beginArray();
    if (simpleType.isPrimitive() || isBoxedClass(simpleType)) {
        while (in.hasNext()){
            list.add(SupportUtils.readPrimitiveOrItsBox(in, property));
        }
    }else{
        TypeAdapter adapter = getTypeAdapter(simpleType);
        while (in.hasNext()){
            list.add(adapter.read(in));
        }
    }
    //copy to array
    Object array = Array.newInstance(simpleType, list.size());
    for(int i = 0, size = list.size() ; i < size ; i ++){
        Array.set(array, i, list.get(i));
    }
    setValue(property, t, array);
    in.endArray();
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:25,代碼來源:TypeHandler.java

示例4: deserialize

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public void deserialize(JsonReader reader) throws IOException {
    reader.beginObject();

    while (reader.hasNext()) {
        switch (reader.nextName()) {
            case "messages":
                reader.beginArray();
                while(reader.hasNext()) {
                    reader.beginObject();
                    MessageEntry entry = new MessageEntry(UUID.fromString(reader.nextName()));
                    entry.deserialize(reader);
                    messages.add(entry);
                    reader.endObject();
                }
                reader.endArray();
                break;
            default: break;
        }
    }

    reader.endObject();
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:24,代碼來源:CustomMessageEntry.java

示例5: getJobProperties

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
private JobProperties getJobProperties(final JsonReader in) throws IOException {
    JobProperties result = new JobProperties();
    in.beginObject();
    while (in.hasNext()) {
        switch (in.nextName()) {
            case "job_exception_handler":
                result.put(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER.getKey(), in.nextString());
                break;
            case "executor_service_handler":
                result.put(JobProperties.JobPropertiesEnum.EXECUTOR_SERVICE_HANDLER.getKey(), in.nextString());
                break;
            default:
                break;
        }
    }
    in.endObject();
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:19,代碼來源:AbstractJobConfigurationGsonTypeAdapter.java

示例6: readNonNull

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
protected Set<T> readNonNull(JsonReader in) throws IOException {
    final EnumSet<T> set = EnumSet.noneOf(type);
    in.beginArray();
    while(in.hasNext()) {
        final String name = in.nextString();
        final T element;
        try {
            element = Enum.valueOf(type, name);
        } catch(IllegalArgumentException e) {
            continue;
        }
        set.add(element);
    }
    in.endArray();
    return set;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:18,代碼來源:LenientEnumSetTypeAdapter.java

示例7: readHistoryJson

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public List<Address> readHistoryJson(final InputStream in) throws JsonParsingException {
    try {
        JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
        List<Address> addresses = new ArrayList<>();
        reader.beginArray();
        while (reader.hasNext()) {
            Address message = gson.fromJson(reader, Address.class);
            addresses.add(message);
        }
        reader.endArray();
        reader.close();
        return addresses;
    } catch (Exception e) {
        throw new JsonParsingException(e);
    }
}
 
開發者ID:RacZo,項目名稱:Smarty-Streets-AutoCompleteTextView,代碼行數:18,代碼來源:GsonSmartyStreetsApiJsonParser.java

示例8: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public ProcessType read(JsonReader in) throws IOException {
    if (!in.hasNext()) {
        return null;
    }
    return ProcessType.fromString(in.nextString());
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:8,代碼來源:ProcessTypeJsonAdapter.java

示例9: parseResults

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
private void parseResults(JsonReader reader, JsonWriter writer) throws IOException
{
	reader.beginArray();
	while (reader.hasNext())
	{
		MetricFrom metricFrom = gson.fromJson(reader, MetricFrom.class);
		MetricTo metricTo = new MetricTo(metricFrom);
		gson.toJson(metricTo, MetricTo.class, writer);
	}

	reader.endArray();
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:13,代碼來源:ResponseToMetricConverter.java

示例10: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
public Collection<E> read(JsonReader in) throws IOException {
  if (in.peek() == JsonToken.NULL) {
    in.nextNull();
    return null;
  }

  Collection<E> collection = constructor.construct();
  in.beginArray();
  while (in.hasNext()) {
    E instance = elementTypeAdapter.read(in);
    collection.add(instance);
  }
  in.endArray();
  return collection;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:CollectionTypeAdapterFactory.java

示例11: readStringArray

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
public List<String> readStringArray(JsonReader reader) throws IOException {
    List<String> colors = new ArrayList<String>();
 
    reader.beginArray();
    while (reader.hasNext()) {
        colors.add(reader.nextString());
    }
    reader.endArray();
    return colors;
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:11,代碼來源:Car3TypeAdapter.java

示例12: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public List<Car3> read(JsonReader in) throws IOException {
    List<Car3> list = new ArrayList<>();
    in.beginArray();
    while (in.hasNext()){
        switch (in.peek()){
            case BEGIN_OBJECT:
               // log("BEGIN_OBJECT");
                list.add(mAdapter.read(in));
                break;
        }
    }
    in.endArray();
    return list;
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:16,代碼來源:ListCar3TypeAdapter.java

示例13: read

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override public Object read(JsonReader in) throws IOException {
  JsonToken token = in.peek();
  switch (token) {
  case BEGIN_ARRAY:
    List<Object> list = new ArrayList<Object>();
    in.beginArray();
    while (in.hasNext()) {
      list.add(read(in));
    }
    in.endArray();
    return list;

  case BEGIN_OBJECT:
    Map<String, Object> map = new LinkedTreeMap<String, Object>();
    in.beginObject();
    while (in.hasNext()) {
      map.put(in.nextName(), read(in));
    }
    in.endObject();
    return map;

  case STRING:
    return in.nextString();

  case NUMBER:
    return in.nextDouble();

  case BOOLEAN:
    return in.nextBoolean();

  case NULL:
    in.nextNull();
    return null;

  default:
    throw new IllegalStateException();
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:ObjectTypeAdapter.java

示例14: deserialize

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
@Override
public void deserialize(JsonReader reader) throws IOException {
    reader.beginObject();

    while(reader.hasNext()) {
        switch (reader.nextName()) {
            case "enabled":
                setEnabled(reader.nextBoolean());
                break;
            case "keyword":
                setKeyword(reader.nextString());
                break;
            case "type":
                setType(reader.nextString());
                break;
            case "trigger":
                setTrigger(reader.nextString());
                break;
            case "delay":
                setDelay(reader.nextLong());
                break;
            case "messages":
                reader.beginArray();
                while(reader.hasNext()) {
                    add(reader.nextString());
                }
                reader.endArray();
                break;
            default: break;
        }
    }

    reader.endObject();
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:35,代碼來源:SpamEntry.java

示例15: readStringArray

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
public List<String> readStringArray(JsonReader reader) throws IOException {
    List<String> colors = new ArrayList<String>();
    reader.beginArray();
    while (reader.hasNext()) {
        colors.add(reader.nextString());
    }
    reader.endArray();
    return colors;
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:10,代碼來源:StringArrayAdapter.java


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