当前位置: 首页>>代码示例>>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;未经允许,请勿转载。