本文整理汇总了Java中com.google.gson.stream.JsonReader.beginArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.beginArray方法的具体用法?Java JsonReader.beginArray怎么用?Java JsonReader.beginArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.beginArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Object read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
List<E> list = new ArrayList<E>();
in.beginArray();
while (in.hasNext()) {
E instance = componentTypeAdapter.read(in);
list.add(instance);
}
in.endArray();
Object array = Array.newInstance(componentType, list.size());
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
return array;
}
示例2: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Object read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
List<E> list = new ArrayList();
in.beginArray();
while (in.hasNext()) {
list.add(this.componentTypeAdapter.read(in));
}
in.endArray();
Object array = Array.newInstance(this.componentType, list.size());
for (int i = 0; i < list.size(); i++) {
Array.set(array, i, list.get(i));
}
return array;
}
示例3: 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;
}
示例4: 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
示例5: 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;
}
示例6: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override
public void deserialize(JsonReader reader) throws IOException {
reader.beginArray();
while(reader.hasNext()) {
add(reader.nextString());
}
reader.endArray();
}
示例7: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
@Override public JsonElement read(JsonReader in) throws IOException {
switch (in.peek()) {
case STRING:
return new JsonPrimitive(in.nextString());
case NUMBER:
String number = in.nextString();
return new JsonPrimitive(new LazilyParsedNumber(number));
case BOOLEAN:
return new JsonPrimitive(in.nextBoolean());
case NULL:
in.nextNull();
return JsonNull.INSTANCE;
case BEGIN_ARRAY:
JsonArray array = new JsonArray();
in.beginArray();
while (in.hasNext()) {
array.add(read(in));
}
in.endArray();
return array;
case BEGIN_OBJECT:
JsonObject object = new JsonObject();
in.beginObject();
while (in.hasNext()) {
object.add(in.nextName(), read(in));
}
in.endObject();
return object;
case END_DOCUMENT:
case NAME:
case END_OBJECT:
case END_ARRAY:
default:
throw new IllegalArgumentException();
}
}
示例8: 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;
}
示例9: 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);
}
示例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 = (Collection) this.constructor.construct();
in.beginArray();
while (in.hasNext()) {
collection.add(this.elementTypeAdapter.read(in));
}
in.endArray();
return collection;
}
示例11: 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();
}
}
示例12: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public Map<K, V> read(JsonReader in) throws IOException {
JsonToken peek = in.peek();
if (peek == JsonToken.NULL) {
in.nextNull();
return null;
}
Map<K, V> map = (Map) this.constructor.construct();
K key;
if (peek == JsonToken.BEGIN_ARRAY) {
in.beginArray();
while (in.hasNext()) {
in.beginArray();
key = this.keyTypeAdapter.read(in);
if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
throw new JsonSyntaxException("duplicate key: " + key);
}
in.endArray();
}
in.endArray();
return map;
}
in.beginObject();
while (in.hasNext()) {
JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in);
key = this.keyTypeAdapter.read(in);
if (map.put(key, this.valueTypeAdapter.read(in)) != null) {
throw new JsonSyntaxException("duplicate key: " + key);
}
}
in.endObject();
return map;
}
示例13: read
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public JsonElement read(JsonReader in) throws IOException {
switch (in.peek()) {
case NUMBER:
return new JsonPrimitive(new LazilyParsedNumber(in.nextString()));
case BOOLEAN:
return new JsonPrimitive(Boolean.valueOf(in.nextBoolean()));
case STRING:
return new JsonPrimitive(in.nextString());
case NULL:
in.nextNull();
return JsonNull.INSTANCE;
case BEGIN_ARRAY:
JsonElement array = new JsonArray();
in.beginArray();
while (in.hasNext()) {
array.add(read(in));
}
in.endArray();
return array;
case BEGIN_OBJECT:
JsonElement object = new JsonObject();
in.beginObject();
while (in.hasNext()) {
object.add(in.nextName(), read(in));
}
in.endObject();
return object;
default:
throw new IllegalArgumentException();
}
}
示例14: 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();
}
}
示例15: 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 LinkedTreeMap();
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();
}
}