本文整理汇总了Java中com.google.gson.stream.JsonReader.beginObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.beginObject方法的具体用法?Java JsonReader.beginObject怎么用?Java JsonReader.beginObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.beginObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override public AnInterface read(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
String name = null;
while (jsonReader.peek() != JsonToken.END_OBJECT) {
switch (jsonReader.nextName()) {
case "name":
name = jsonReader.nextString();
break;
}
}
jsonReader.endObject();
return new AnImplementation(name);
}
示例3: 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);
}
示例4: 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<>();
in.beginArray();
while (in.hasNext()) {
list.add(read(in));
}
in.endArray();
return list;
case BEGIN_OBJECT:
Map<String, Object> map = new LinkedTreeMap<>();
in.beginObject();
while (in.hasNext()) {
map.put(in.nextName(), read(in));
}
in.endObject();
return map;
case STRING:
return in.nextString();
case NUMBER:
return getNumber(in.nextString());
case BOOLEAN:
return in.nextBoolean();
case NULL:
in.nextNull();
return null;
default:
throw new IllegalStateException();
}
}
示例5: 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();
}
}
示例6: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public Color read(JsonReader i) throws IOException {
int red = 0;
int green = 0;
int blue = 0;
int alpha = 0;
i.beginObject();
while (i.hasNext()) {
switch (i.nextName()) {
case "red":
red = i.nextInt();
break;
case "green":
green = i.nextInt();
break;
case "blue":
blue = i.nextInt();
break;
case "alpha":
alpha = i.nextInt();
break;
}
}
i.endObject();
if (red > 255) red = 255;
if (green > 255) green = 255;
if (blue > 255) blue = 255;
if (alpha > 255) alpha = 255;
Color c = new Color(red, green, blue, alpha);
return c;
}
示例7: 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 "msg":
setMessage(reader.nextString());
break;
}
}
reader.endObject();
}
示例8: 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);
}
示例9: 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();
}
示例10: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public void deserialize(JsonReader reader) throws IOException {
reader.beginObject();
reader.nextName(); // value
rawSet(reader.nextString(), true);
reader.endObject();
}
示例11: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public SparseArray<Car3> read(JsonReader in) throws IOException {
SparseArray<Car3> map = new SparseArray<>();
in.beginObject();
while (in.hasNext()){
String name = in.nextName();
map.put(Integer.parseInt(name), mAdapter.read(in));
}
in.endObject();
return map;
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
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);
}
示例13: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Object read(JsonReader in) throws IOException {
switch (in.peek()) {
case BEGIN_ARRAY:
List<Object> list = new ArrayList();
in.beginArray();
while (in.hasNext()) {
list.add(read(in));
}
in.endArray();
return list;
case BEGIN_OBJECT:
Map<String, Object> map = new LinkedHashMap();
in.beginObject();
while (in.hasNext()) {
map.put(in.nextName(), read(in));
}
in.endObject();
return map;
case STRING:
return in.nextString();
case NUMBER:
return Double.valueOf(in.nextDouble());
case BOOLEAN:
return Boolean.valueOf(in.nextBoolean());
case NULL:
in.nextNull();
return null;
default:
throw new IllegalStateException();
}
}
示例14: 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);
}
示例15: readUnion
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private T readUnion(
final JsonReader in
) throws IOException, InstantiationException, IllegalAccessException {
// assert begin of object
in.beginObject();
// create new union with default values
T union = (T) unionClass.newInstance();
// gets populated when active branch is known
UnionMemberInfo unionMemberInfo = null;
while (in.hasNext()) {
// get name of next item
String name = in.nextName();
if (DISCRIMINATOR_FIELD_NAME.equals(name)) {
// read discriminator
Object discriminatorObject = discriminatorTypeAdapter.read(in);
// if discriminator is not valid, return union with defaults
if (discriminatorObject == null) {
// skip remaining values
while (in.hasNext()) {
in.skipValue();
}
// assert end of object
in.endObject();
// return empty union with default values
return union;
}
// remember discriminator
unionMemberInfo = memberInfoMap.get(discriminatorObject.toString());
// set discriminator on union
fieldAccess.set(union, DISCRIMINATOR_FIELD_NAME, discriminatorObject);
} else if (unionMemberInfo != null
&& unionMemberInfo.fieldName.equals(name)) {
Object fieldObject = unionMemberInfo.typeAdapter.read(in);
fieldAccess.set(union, unionMemberInfo.fieldName, fieldObject);
} else {
in.skipValue();
}
}
// assert end of object
in.endObject();
// return result
return union;
}