當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonReader.beginObject方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:ReflectiveTypeAdapterFactory.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:GsonConverterFactoryTest.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:33,代碼來源:TypeAdapters.java

示例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();
    }
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:34,代碼來源:NumberPredictObjectTypeAdapterFactory.java

示例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();
  }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:39,代碼來源:ObjectTypeAdapter.java

示例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;
}
 
開發者ID:gabixdev,項目名稱:Kyoko,代碼行數:36,代碼來源:ColorTypeAdapter.java

示例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();
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:15,代碼來源:CustomMessageEntry.java

示例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);
}
 
開發者ID:SERESLab,項目名稱:iTrace-Archive,代碼行數:39,代碼來源:JSONBasicFixationFilter.java

示例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();
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:16,代碼來源:BlockEntry.java

示例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();
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:10,代碼來源:Setting.java

示例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;
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:12,代碼來源:Car3SparseArrayTypeAdapter.java

示例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);
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:34,代碼來源:TypeAdapters.java

示例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();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:32,代碼來源:ObjectTypeAdapter.java

示例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);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:33,代碼來源:TypeAdapters.java

示例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;
}
 
開發者ID:aguther,項目名稱:dds-examples,代碼行數:57,代碼來源:UnionTypeAdapterFactory.java


注:本文中的com.google.gson.stream.JsonReader.beginObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。