当前位置: 首页>>代码示例>>Java>>正文


Java JsonToken.BEGIN_OBJECT属性代码示例

本文整理汇总了Java中android.util.JsonToken.BEGIN_OBJECT属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.BEGIN_OBJECT属性的具体用法?Java JsonToken.BEGIN_OBJECT怎么用?Java JsonToken.BEGIN_OBJECT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.util.JsonToken的用法示例。


在下文中一共展示了JsonToken.BEGIN_OBJECT属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

@Override public PointF parse(JsonReader reader, float scale) throws IOException {
  JsonToken token = reader.peek();
  if (token == JsonToken.BEGIN_ARRAY) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.BEGIN_OBJECT) {
    return JsonUtils.jsonToPoint(reader, scale);
  } else if (token == JsonToken.NUMBER) {
    // This is the case where the static value for a property is an array of numbers.
    // We begin the array to see if we have an array of keyframes but it's just an array
    // of static numbers instead.
    PointF point = new PointF((float) reader.nextDouble() * scale, (float) reader.nextDouble() * scale);
    while (reader.hasNext()) {
      reader.skipValue();
    }
    return point;
  } else {
    throw new IllegalArgumentException("Cannot convert json to point. Next token is " + token);
  }
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:19,代码来源:PointFParser.java

示例2: inflate

/***
 * This method called in the background, here
 * need to parse given {@code json}
 *
 * @param reader Widget configuration
 */
protected void inflate(ConfigurationWidget widget, JsonReader reader) throws IOException {
    Bundle options = new Bundle();
    Bundle configs = widget.getConfigurations();
    JsonToken token = reader.peek();
    if(token == JsonToken.BEGIN_OBJECT){
        appendViewInLayout(createView(this, configs, options, reader));
    }else if (token == JsonToken.BEGIN_ARRAY){
        reader.beginArray();
        while(reader.peek() != JsonToken.END_ARRAY){
            appendViewInLayout(createView(this, configs, options, reader));
            options.clear(); // recycle configurations
        }
        reader.endArray();
    }else{
        throw new RuntimeException("Unsupported token exception: " + reader.toString());
    }
    options.clear();
}
 
开发者ID:ozodrukh,项目名称:Green,代码行数:24,代码来源:ConfigCard.java

示例3: parse

static PathKeyframe parse(
    JsonReader reader, LottieComposition composition) throws IOException {
  boolean animated = reader.peek() == JsonToken.BEGIN_OBJECT;
  Keyframe<PointF> keyframe = KeyframeParser.parse(
      reader, composition, Utils.dpScale(), PathParser.INSTANCE, animated);

  return new PathKeyframe(composition, keyframe);
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:8,代码来源:PathKeyframeParser.java

示例4: run

@Override
public void run() {
    try {
        m_socket = new Socket(m_hostname, m_port);

        if (m_socket.isConnected()) {
            send(getDeviceDefinition());
            InputStream is = m_socket.getInputStream();
            JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8"));

            reader.beginArray();
            ConnectedMessage connectedMessage = new ConnectedMessage();
            if (connectedMessage.readMessage(reader) && connectedMessage.isConnected) {
                m_listener.onConnectivityUpdate(true);

                if (reader.peek() == JsonToken.BEGIN_OBJECT) {
                    // continue
                    Log.d("infuse", "BEGIN OBJECT");
                } else {
                    Log.d("infuse", reader.peek().toString());
                    Log.d("infuse", reader.nextString());

                }

                reader.endArray();
            }
            m_socket.close();
        }

    } catch (Exception e) {
        if (!m_disconnecting) {
            e.printStackTrace();
            m_listener.onException(e);
        }
    }

    m_listener.onConnectivityUpdate(false);
}
 
开发者ID:backmask,项目名称:timelapse,代码行数:38,代码来源:InfuseSocketWorker.java

示例5: parse

public static AnimatableTransform parse(
    JsonReader reader, LottieComposition composition) throws IOException {
  AnimatablePathValue anchorPoint = null;
  AnimatableValue<PointF, PointF> position = null;
  AnimatableScaleValue scale = null;
  AnimatableFloatValue rotation = null;
  AnimatableIntegerValue opacity = null;
  AnimatableFloatValue startOpacity = null;
  AnimatableFloatValue endOpacity = null;

  boolean isObject = reader.peek() == JsonToken.BEGIN_OBJECT;
  if (isObject) {
    reader.beginObject();
  }
  while (reader.hasNext()) {
    switch (reader.nextName()) {
      case "a":
        reader.beginObject();
        while (reader.hasNext()) {
          if (reader.nextName().equals("k")) {
            anchorPoint = AnimatablePathValueParser.parse(reader, composition);
          } else {
            reader.skipValue();
          }
        }
        reader.endObject();
        break;
      case "p":
        position =
            AnimatablePathValueParser.parseSplitPath(reader, composition);
        break;
      case "s":
        scale = AnimatableValueParser.parseScale(reader, composition);
        break;
      case "rz":
        composition.addWarning("Lottie doesn't support 3D layers.");
      case "r":
        rotation = AnimatableValueParser.parseFloat(reader, composition, false);
        break;
      case "o":
        opacity = AnimatableValueParser.parseInteger(reader, composition);
        break;
      case "so":
        startOpacity = AnimatableValueParser.parseFloat(reader, composition, false);
        break;
      case "eo":
        endOpacity = AnimatableValueParser.parseFloat(reader, composition, false);
        break;
      default:
        reader.skipValue();
    }
  }
  if (isObject) {
    reader.endObject();
  }

  if (anchorPoint == null) {
    // Cameras don't have an anchor point property. Although we don't support them, at least
    // we won't crash.
    Log.w(L.TAG, "Layer has no transform property. You may be using an unsupported " +
        "layer type such as a camera.");
    anchorPoint = new AnimatablePathValue();
  }

  if (scale == null) {
    // Somehow some community animations don't have scale in the transform.
    scale = new AnimatableScaleValue(new ScaleXY(1f, 1f));
  }

  if (opacity == null) {
    // Repeaters have start/end opacity instead of opacity
    opacity = new AnimatableIntegerValue();
  }

  return new AnimatableTransform(
      anchorPoint, position, scale, rotation, opacity, startOpacity, endOpacity);
}
 
开发者ID:airbnb,项目名称:lottie-android,代码行数:77,代码来源:AnimatableTransformParser.java

示例6: parseFlatJsonArray

/**
 * Parse an array that has only non-array children into a {@link Collection}.
 *
 * @param reader The reader to use, whose next token should either be {@link JsonToken#NULL} or
 * {@link JsonToken#BEGIN_ARRAY}.
 * @param collection The Collection to populate. The parametrization should match {@code
 * typeClass}.
 * @param itemParser The parser to use for items of the array. May be null.
 * @param typeClass The type of items to expect in the array. May not be null, but may be
 * Object.class.
 * @param key The key corresponding to the current value. This is used to make more useful error
 * messages.
 */
private static <T> void parseFlatJsonArray(JsonReader reader,
                                           Collection<T> collection,
                                           JsonObjectParser<T> itemParser,
                                           Class<T> typeClass,
                                           String key)
        throws IOException {
    if (handleNull(reader)) {
        return;
    }

    Converter<T> converter = null;
    if (Converters.isConvertibleFromString(typeClass)) {
        converter = Converters.getConverter(typeClass);
    }

    final String discriminationName =
            ContextHolder.getContext().getSettings().getDiscriminationName();

    reader.beginArray();
    while (reader.hasNext()) {
        Object nextValue;
        final JsonToken nextToken = reader.peek();
        if (itemParser != null && nextToken == JsonToken.BEGIN_OBJECT) {
            reader.beginObject();
            nextValue = itemParser.parseJsonObject(null, reader, discriminationName, null);
            reader.endObject();
        } else if (converter != null && (nextToken == JsonToken.NUMBER
                || nextToken == JsonToken.STRING)) {
            nextValue = converter.convert(reader.nextString());
        } else {
            nextValue = parseNextValue(reader);
        }

        if (typeClass.isInstance(nextValue)) {
            // This is safe since we are calling class.isInstance()
            @SuppressWarnings("unchecked")
            T toAdd = (T) nextValue;
            collection.add(toAdd);
        } else if (nextToken == JsonToken.NULL) {
            collection.add(null);
        } else {
            throw new IllegalStateException(
                    String.format(Locale.US,
                                  "Could not convert value in array at \"%s\" to %s from %s.",
                                  key,
                                  typeClass.getCanonicalName(),
                                  getClassName(nextValue)));
        }
    }
    reader.endArray();
}
 
开发者ID:Workday,项目名称:autoparse-json,代码行数:64,代码来源:JsonParserUtils.java


注:本文中的android.util.JsonToken.BEGIN_OBJECT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。