本文整理汇总了Java中com.google.gson.stream.JsonReader.nextString方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.nextString方法的具体用法?Java JsonReader.nextString怎么用?Java JsonReader.nextString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.nextString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public java.sql.Date read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
try {
if (dateFormat != null) {
return new java.sql.Date(dateFormat.parse(date).getTime());
}
return new java.sql.Date(ISO8601Utils.parse(date, new ParsePosition(0)).getTime());
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
}
示例2: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Locale read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
StringTokenizer tokenizer = new StringTokenizer(in.nextString(), EventsFilesManager.ROLL_OVER_FILE_NAME_SEPARATOR);
String language = null;
String country = null;
String variant = null;
if (tokenizer.hasMoreElements()) {
language = tokenizer.nextToken();
}
if (tokenizer.hasMoreElements()) {
country = tokenizer.nextToken();
}
if (tokenizer.hasMoreElements()) {
variant = tokenizer.nextToken();
}
if (country == null && variant == null) {
return new Locale(language);
}
if (variant == null) {
return new Locale(language, country);
}
return new Locale(language, country, variant);
}
示例3: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public StringBuilder read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
return new StringBuilder(in.nextString());
}
示例4: gson
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Benchmark
public void gson(Blackhole bh) throws Exception {
JsonReader reader = new JsonReader(new CharArrayReader(chars));
while (true) {
JsonToken token = reader.peek();
switch (token) {
case BEGIN_ARRAY:
reader.beginArray();
break;
case END_ARRAY:
reader.endArray();
break;
case BEGIN_OBJECT:
reader.beginObject();
break;
case END_OBJECT:
reader.endObject();
break;
case NAME:
reader.nextName();
break;
case STRING:
reader.nextString();
break;
case NUMBER:
reader.nextString();
break;
case BOOLEAN:
reader.nextBoolean();
break;
case NULL:
reader.nextNull();
break;
case END_DOCUMENT:
reader.close();
return;
}
}
}
示例5: readNext
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
protected String readNext(final String name, final JsonReader reader) throws IOException {
if(reader.peek() != JsonToken.NULL) {
return reader.nextString();
}
else {
reader.skipValue();
log.warn(String.format("No value for key %s", name));
return null;
}
}
示例6: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public PlayerId read(JsonReader in) throws IOException {
in.beginArray();
String player_id = in.nextString();
String username = in.nextString();
String _id = in.nextString();
in.endArray();
return new SimplePlayerId(_id, player_id, username);
}
示例7: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public DOrderAction read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
String value = reader.nextString();
return DOrderAction.getOrderByValue(value);
}
示例8: 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();
}
示例9: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public DateTime read(JsonReader in) throws IOException {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
return parseFormatter.parseDateTime(date);
}
}
示例10: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public String read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return "";
}
return in.nextString();
}
示例11: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public URI read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
try {
String nextString = in.nextString();
return "null".equals(nextString) ? null : new URI(nextString);
} catch (URISyntaxException e) {
throw new JsonIOException(e);
}
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public TransactionID read(JsonReader in) throws IOException {
return new TransactionID(in.nextString());
}
示例13: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public ObjectEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return ObjectEnum.fromValue(String.valueOf(value));
}
示例14: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public OrderSpecifier read(JsonReader in) throws IOException {
return new OrderSpecifier(in.nextString());
}
示例15: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T read(JsonReader in) throws IOException {
Object res;
in.beginObject();
LOG.info(in.nextName());
String clazzName = in.nextString();
LOG.info(clazzName);
LOG.info(in.nextName());
try {
Class<?> typeOfT = Class.forName(clazzName);
// TypeAdapter<?> del = gson.getDelegateAdapter(new ObjectTypeAdapterFactory(),
// );
TypeAdapter<?> del = gson.getAdapter(TypeToken.get(typeOfT));
LOG.info("ta: " + del + " taDel: " + delegate + " tt: " + TypeToken.get(typeOfT));
if (typeOfT.isArray()) {
del = com.google.gson.internal.bind.ArrayTypeAdapter.FACTORY.create(gson, TypeToken.get(typeOfT));
} else {
del = delegate;
}
JsonToken peek = in.peek();
switch (peek) {
case STRING:
res = in.nextString();
break;
case BOOLEAN:
res = in.nextBoolean();
break;
case NUMBER:
if (Long.class.equals(typeOfT)) {
res = in.nextLong();
} else if (Integer.class.equals(typeOfT)) {
res = in.nextInt();
} else {
res = in.nextDouble();
}
break;
default:
res = (T) del.read(in);
}
} catch (ClassNotFoundException e) {
throw new JsonParseException(e);
}
// res = delegate.read(in);
in.endObject();
return (T) res;
}