本文整理汇总了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();
}
}
示例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);
}
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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());
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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;
}