本文整理汇总了Java中com.google.gson.stream.JsonReader.nextName方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.nextName方法的具体用法?Java JsonReader.nextName怎么用?Java JsonReader.nextName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.nextName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public void deserialize(JsonReader reader) throws IOException {
reader.beginObject();
reader.nextName(); // data
reader.beginObject();
while(reader.hasNext()) {
String name = reader.nextName();
E element = factory.apply(name);
if(element != null) {
element.deserialize(reader);
add(element);
}
}
reader.endObject();
reader.endObject();
}
示例3: 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;
}
示例4: parseResponse
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* 太绕,还是直接用Json解析吧
*
* @param response
* @throws IOException
*/
private void parseResponse(Reader response) throws IOException {
JsonReader reader = new JsonReader(response);
reader.beginObject();
String name;
while (reader.hasNext()) {
name = reader.nextName();
if (TextUtils.equals(Field.ERROR, name)) {
reader.nextInt();
} else if (TextUtils.equals(Field.MESSAGE, name)) {
reader.nextString();
} else if (TextUtils.equals(Field.DATA, name)) {
reader.beginObject();
while (reader.hasNext()) {
reader.nextName();
reader.beginArray();
while (reader.hasNext()) {
reader.beginObject();
String itemObjKey;
while (reader.hasNext()) {
itemObjKey = reader.nextName();
if (TextUtils.equals(Field.TOKEN, itemObjKey)) {
reader.nextString();
} else {
reader.skipValue();
}
}
reader.endObject();
}
reader.endArray();
}
reader.endObject();
} else {
reader.skipValue();
}
}
reader.endObject();
reader.close();
}
示例5: getSce
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public SourceCodeEntity getSce(JsonReader reader) throws IOException {
String name = new String();
String type = new String();
String how = new String();
int length = -1;
int startLine = -1;
int endLine = -1;
int startCol = -1;
int endCol = -1;
reader.beginObject();
while(reader.hasNext()) {
String Name = reader.nextName();
if (Name.equals("name")) {
name = reader.nextString();
} else if (Name.equals("type")) {
type = reader.nextString();
} else if (Name.equals("how")) {
how = reader.nextString();
} else if (Name.equals("total_length")) {
length = reader.nextInt();
} else if (Name.equals("start_line")) {
startLine = reader.nextInt();
} else if (Name.equals("end_line")) {
endLine = reader.nextInt();
} else if (Name.equals("start_col")) {
startCol = reader.nextInt();
} else if (Name.equals("end_col")) {
endCol = reader.nextInt();
} else {
reader.skipValue();
}
}
reader.endObject();
return new SourceCodeEntity(name, type, how, length,
startLine, endLine, startCol, endCol);
}
示例6: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public void deserialize(final JsonReader reader) throws IOException {
reader.beginObject();
while(reader.hasNext()) {
String name = reader.nextName();
IBlockProperty property = PropertyFactory.newInstance(name);
if(property != null) {
property.deserialize(reader);
registerProperty(property);
} else {
LOGGER.warn(String.format("\"%s\" is not a valid property name", name));
}
}
reader.endObject();
}
示例7: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Location read(JsonReader in) throws IOException {
in.beginObject();
Double x = null, y = null, z = null, pitch = null, yaw = null;
World world = null;
while (in.hasNext()) {
String s = in.nextName();
if (s.equals(WORLD_KEY)) {
UUID uuid = UUID.fromString(in.nextString());
world = Bukkit.getWorld(uuid);
if (world == null)
throw new JsonParseException("Could not find the world by the UUID: " + uuid.toString());
continue;
}
double v = in.nextDouble();
switch (s) {
case X_KEY:
x = v;
break;
case Y_KEY:
y = v;
break;
case Z_KEY:
z = v;
break;
case PITCH:
pitch = v;
break;
case YAW:
yaw = v;
break;
}
}
in.endObject();
if (world == null || x == null || y == null || z == null || pitch == null || yaw == null)
throw new JsonParseException("Could not read Location object, missing a critical value (expecting world, x, y, z, p, ya)");
return new Location(world, x, y, z, yaw.floatValue(), pitch.floatValue());
}
示例8: 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 "tag":
setTag(reader.nextString());
break;
case "color":
setColor(reader.nextInt());
break;
case "filtered":
reader.beginObject();
// TODO: factory
while(reader.hasNext()) {
try {
E instance = FilterFactory.newInstanceByName(reader.nextName());
add(instance);
} catch (Throwable t) {
Helper.handleThrowable(t);
}
}
reader.endObject();
break;
}
}
reader.endObject();
}
示例9: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Location read(JsonReader in) throws IOException {
World w = null;
String worldString = "";
double x = 0, y = 0, z = 0;
float yaw = 0, pitch = 0;
in.beginObject();
while (in.hasNext()) {
switch (in.nextName()) {
case "x":
x = in.nextDouble();
break;
case "y":
y = in.nextDouble();
break;
case "z":
z = in.nextDouble();
break;
case "yaw":
yaw = (float) in.nextDouble();
break;
case "pitch":
pitch = (float) in.nextDouble();
break;
case "worldString":
worldString = in.nextString();
break;
}
}
in.endObject();
w = SakiCore.plugin.getServer().getWorld(worldString);
if (w == null)
throw new IOException("Invalid world in JSON: " + worldString + ".");
return new Location(w, x, y, z, yaw, pitch);
}
示例10: build
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
protected Page build(JsonReader reader) throws IOException {
Page page = new Page();
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("pageid")) {
page.id = reader.nextLong();
} else if (key.equals("title")) {
page.title = reader.nextString();
} else {
reader.skipValue();
}
}
return page;
}
示例11: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Calendar read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
in.beginObject();
int year = 0;
int month = 0;
int dayOfMonth = 0;
int hourOfDay = 0;
int minute = 0;
int second = 0;
while (in.peek() != JsonToken.END_OBJECT) {
String name = in.nextName();
int value = in.nextInt();
if (YEAR.equals(name)) {
year = value;
} else if (MONTH.equals(name)) {
month = value;
} else if (DAY_OF_MONTH.equals(name)) {
dayOfMonth = value;
} else if (HOUR_OF_DAY.equals(name)) {
hourOfDay = value;
} else if (MINUTE.equals(name)) {
minute = value;
} else if (SECOND.equals(name)) {
second = value;
}
}
in.endObject();
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public SparseArray<T> read(JsonReader in) throws IOException {
SparseArray<T> map = new SparseArray<>();
in.beginObject();
while (in.hasNext()){
String name = in.nextName();
map.put(Integer.parseInt(name), mAdapter.read(in));
}
in.endObject();
return map;
}
示例13: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Calendar read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
in.beginObject();
int year = 0;
int month = 0;
int dayOfMonth = 0;
int hourOfDay = 0;
int minute = 0;
int second = 0;
while (in.peek() != JsonToken.END_OBJECT) {
String name = in.nextName();
int value = in.nextInt();
if ("year".equals(name)) {
year = value;
} else if ("month".equals(name)) {
month = value;
} else if (DAY_OF_MONTH.equals(name)) {
dayOfMonth = value;
} else if (HOUR_OF_DAY.equals(name)) {
hourOfDay = value;
} else if ("minute".equals(name)) {
minute = value;
} else if (SECOND.equals(name)) {
second = value;
}
}
in.endObject();
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
}
示例14: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Location read(JsonReader in) throws IOException
{
in.beginObject();
in.nextName();
double x = in.nextDouble();
in.nextName();
double y = in.nextDouble();
in.nextName();
double z = in.nextDouble();
in.nextName();
float pitch = Float.valueOf(String.valueOf(in.nextDouble()));
in.nextName();
float yaw = Float.valueOf(String.valueOf(in.nextDouble()));
in.nextName();
World world = Bukkit.getWorld(in.nextString());
in.endObject();
return new Location(world, x, y, z, pitch, yaw);
}
示例15: loadFromReader
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static List<Record> loadFromReader(Reader reader) throws IOException {
List<Record> rv = new ArrayList<>();
JsonReader jsonReader = new JsonReader(reader);
jsonReader.beginArray();
while (jsonReader.hasNext()) {
Map<String, String> stringFields = new HashMap<>();
Map<String, LocalDateTime> timeFields = new HashMap<>();
Map<String, List<Double>> doubleListFields = new HashMap<>();
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String key = jsonReader.nextName();
switch (key) {
case ALGORITHM_ID:
case DATASET_ID:
case MEASUREMENT_METHOD:
case MEASUREMENT_AUTHOR:
case CPU_MODEL_NAME:
case COMMENT:
case JAVA_RUNTIME_VERSION:
stringFields.put(key, jsonReader.nextString());
break;
case MEASUREMENT_TIME:
timeFields.put(key, LocalDateTime.parse(jsonReader.nextString()));
break;
case MEASUREMENTS: {
List<Double> list = new ArrayList<>();
jsonReader.beginArray();
while (jsonReader.hasNext()) {
list.add(jsonReader.nextDouble());
}
jsonReader.endArray();
doubleListFields.put(MEASUREMENTS, list);
break;
}
default:
throw new IOException("In record description, stream contains JSON name '" + key
+ "' which is not allowed");
}
}
jsonReader.endObject();
for (String s : ALL_NAMES) {
if (!stringFields.containsKey(s) && !timeFields.containsKey(s) && !doubleListFields.containsKey(s)) {
throw new IOException("In record description, JSON name '" + s + "' is missing");
}
}
rv.add(new Record(stringFields.get(ALGORITHM_ID), stringFields.get(DATASET_ID),
stringFields.get(MEASUREMENT_METHOD), stringFields.get(MEASUREMENT_AUTHOR),
timeFields.get(MEASUREMENT_TIME), stringFields.get(CPU_MODEL_NAME),
stringFields.get(JAVA_RUNTIME_VERSION), doubleListFields.get(MEASUREMENTS),
stringFields.get(COMMENT)));
}
jsonReader.endArray();
return rv;
}