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


Java JSON类代码示例

本文整理汇总了Java中defrac.json.JSON的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: collectResourceGroup

import defrac.json.JSON; //导入依赖的package包/类
@Nonnull
private static ResourceGroup<TextureData> collectResourceGroup( @Nonnull final JSONArray jsonTilesets )
{
	final ResourceGroup<TextureData> textureResources = new ResourceGroup<>( jsonTilesets.length() );

	for( JSON json : jsonTilesets )
	{
		final JSONObject jsonTileset = checkNotNull( json.asObject() );

		final String image = checkNotNull( jsonTileset.getString( "image" ) );

		textureResources.add( TextureDataResource.from( image ) );
	}

	return textureResources;
}
 
开发者ID:andremichelle,项目名称:platforms,代码行数:17,代码来源:MapResources.java

示例2: decodeObjects

import defrac.json.JSON; //导入依赖的package包/类
@Nonnull
private static List<MapObject> decodeObjects( @Nonnull final JSONArray jsonArray )
{
	final ArrayList<MapObject> mapObjects = Lists.newArrayList( jsonArray.length() );

	for( final JSON json : jsonArray )
	{
		final MapObject mapObject = decodeObject( checkNotNull( json.asObject() ) );

		if( null != mapObject )
		{
			mapObjects.add( mapObject );
		}
	}

	return mapObjects;
}
 
开发者ID:andremichelle,项目名称:platforms,代码行数:18,代码来源:MapResources.java

示例3: decodeTileSets

import defrac.json.JSON; //导入依赖的package包/类
@Nonnull
private static TileSet[] decodeTileSets( @Nonnull final JSONArray jsonArray, @Nonnull final List<TextureData> textures )
{
	final TileSet[] tileSets = new TileSet[ jsonArray.length() ];

	int index = 0;

	for( final JSON json : jsonArray )
	{
		final JSONObject jsonObject = json.asObject();

		if( null == jsonObject )
			throw new RuntimeException( "Broken Json" );

		tileSets[ index ] = decodeTileSet( jsonObject, textures.get( index ) );

		index++;
	}

	return tileSets;
}
 
开发者ID:andremichelle,项目名称:platforms,代码行数:22,代码来源:MapResources.java

示例4: resolvePercentage

import defrac.json.JSON; //导入依赖的package包/类
float resolvePercentage(final float parentValue, @Nullable final JSON childValue) {
  if(childValue == null) {
    return Float.NaN;
  }

  if(childValue.isString()) {
    final String stringValue = interpolateString(childValue.stringValue());
    final int indexOfLastChar = stringValue.length() - 1;

    if(indexOfLastChar < 0) {
      throw new LayoutException("Empty string value");
    }

    final int firstChar = stringValue.charAt(0);

    if(stringValue.indexOf('%') == indexOfLastChar && firstChar >= '0' && firstChar <= '9') {
      return parentValue * 0.01f * Float.parseFloat(stringValue.substring(0, indexOfLastChar));
    }
  }

  return resolveValue(childValue);
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:23,代码来源:LayoutContext.java

示例5: resolveValue

import defrac.json.JSON; //导入依赖的package包/类
float resolveValue(@Nonnull final JSON value) {
  if(value.isString()) {
    final String stringValue = interpolateString(value.stringValue());

    if(stringValue.isEmpty()) {
      throw new LayoutException("Empty string value");
    }

    if(stringValue.charAt(0) == '#') {
      return Color.valueOf(stringValue);
    }

    return parser.parse(stringValue).evaluate(this);
  }

  return value.floatValue();
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:18,代码来源:LayoutContext.java

示例6: inflate

import defrac.json.JSON; //导入依赖的package包/类
public Future<Void> inflate(@Nonnull final DisplayObjectContainer root,
                            @Nonnull final JSON layout,
                            @Nonnull final Dispatcher dispatcher,
                            final float availableWidth,
                            final float availableHeight) {
  if(!layout.isObject()) {
    Futures.failure(new LayoutException("Given layout isn't a JSON object"));
  }

  context.dispatcher(dispatcher);

  final JSONObject layoutObject = (JSONObject)layout;

  inflateConstants(layoutObject);

  return inflateChildren(root, layoutObject, availableWidth, availableHeight);
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:18,代码来源:LayoutInflater.java

示例7: inflateDescriptors

import defrac.json.JSON; //导入依赖的package包/类
/**
 * Inflates an array of descriptors into a parent
 *
 * <p>This method should only be called from {@link #inflateRepetition(DisplayObjectContainer, JSONObject, int)}
 * and not manually.
 *
 * @param parent The parent
 * @param descriptors The array of descriptors
 *
 * @return The Future representing the completion of inflating the descriptors
 */
@Nonnull
private Future<Void> inflateDescriptors(@Nonnull final DisplayObjectContainer parent,
                                        @Nonnull final JSONArray descriptors) {
  final int descriptorCount = descriptors.length();

  final Future<Void> future;

  if(0 == descriptorCount) {
    future = success();
  } else if(1 == descriptorCount) {
    final JSON firstChild = descriptors.get(0);

    if(firstChild == null || !firstChild.isObject()) {
      future = success();
    } else {
      future = inflate(parent, (JSONObject)firstChild);
    }
  } else {
    future = inflateDescriptorsTrampoline(parent, descriptors, 0, descriptorCount);
  }

  return future;
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:35,代码来源:LayoutInflater.java

示例8: inflateDescriptorsTrampoline

import defrac.json.JSON; //导入依赖的package包/类
/**
 * Trampoline for asynchronous inflation of an array of descriptors into a parent
 *
 * @param parent The parent
 * @param descriptors The descriptor
 * @param descriptorIndex The current index in the descriptors array
 * @param descriptorCount The length of the descriptors array
 *
 * @return The Future representing the completion of inflating the descriptor {@code repeatCount - repeatIndex} times
 */
@Nonnull
private Future<Void> inflateDescriptorsTrampoline(@Nonnull final DisplayObjectContainer parent,
                                                  @Nonnull final JSONArray descriptors,
                                                  final int descriptorIndex,
                                                  final int descriptorCount) {
  final JSON descriptor = descriptors.get(descriptorIndex);
  final Future<Void> future = inflate(parent, descriptor == null ? null : descriptor.asObject());

  return future.flatMap(theVoid -> {
    final int nextDescriptorIndex = descriptorIndex + 1;

    if(nextDescriptorIndex == descriptorCount) {
      return success();
    } else {
      return inflateDescriptorsTrampoline(parent, descriptors, nextDescriptorIndex, descriptorCount);
    }
  }, context.dispatcher());
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:29,代码来源:LayoutInflater.java

示例9: readCurve

import defrac.json.JSON; //导入依赖的package包/类
private static void readCurve(@Nonnull final CurveTimeline timeline,
                              final int frameIndex,
                              @Nonnull final JSONObject valueMap) {
  final JSON curve = valueMap.opt("curve");

  if(curve.isString() && "stepped".equals(curve.stringValue())) {
    timeline.setSteppedAt(frameIndex);
  } else if (curve.isArray()) {
    final JSONArray curveArray = (JSONArray)curve;

    timeline.setCurve(
        frameIndex,
        curveArray.getFloat(0), curveArray.getFloat(1),
        curveArray.getFloat(2), curveArray.getFloat(3));
  }
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:17,代码来源:SkeletonJson.java

示例10: initWithStage

import defrac.json.JSON; //导入依赖的package包/类
@Override
protected void initWithStage(@Nonnull final Stage stage) {
  final Future<TextureAtlas> atlasFuture =
      LibgdxTextureAtlasResource.from(
          "raptor/raptor.atlas",
          TextureDataSupplies.premultipliedResource("raptor/")
      ).load();

  final Future<JSON> jsonFuture =
      JSON.parse(StringResource.from("raptor/raptor.json"));

  final Future<SkeletonData> dataFuture =
    atlasFuture.
        join(jsonFuture).
        map(pair -> {
          final SkeletonJson json = new SkeletonJson(pair.x);
          json.scale(0.5f);
          return json.readSkeletonData((JSONObject)pair.y);
        });

  dataFuture.
      onSuccess(this::init).
      onFailure(Procedures.printStackTrace());
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:25,代码来源:SpineRaptorSample.java

示例11: apply

import defrac.json.JSON; //导入依赖的package包/类
@Override
public DefracPlatform[] apply(@Nullable final JSON json) {
  final String[] strings = JSON_ARRAY_TO_STRING_ARRAY.apply(json);

  if(strings == null) {
    return null;
  }

  final ArrayList<DefracPlatform> platforms = Lists.newArrayListWithExpectedSize(strings.length);

  for(final String string : strings) {
    if("android".equalsIgnoreCase(string)) {
      platforms.add(DefracPlatform.ANDROID);
    } else if("ios".equalsIgnoreCase(string)) {
      platforms.add(DefracPlatform.IOS);
    } else if("jvm".equalsIgnoreCase(string)) {
      platforms.add(DefracPlatform.JVM);
    } else if("web".equalsIgnoreCase(string)) {
      platforms.add(DefracPlatform.WEB);
    }
  }

  return platforms.toArray(new DefracPlatform[platforms.size()]);
}
 
开发者ID:defrac,项目名称:defrac-plugin-intellij,代码行数:25,代码来源:DefracConfigOracle.java

示例12: extract

import defrac.json.JSON; //导入依赖的package包/类
@Nullable
private <A> A extract(@NotNull final String fieldPath,
                      @NotNull final Class<A> typeOfValue,
                      @NotNull final Function<JSON, A> flattener,
                      @NotNull final JSON genericConfig) throws NoSuchFieldException, IllegalAccessException {
  final JSON platformConfig =
      genericConfig.asObject(JSONObject.EMPTY).optObject(platform.name);

  if(platformConfig != JSONObject.EMPTY) {
    try {
      final A value = walkPath(fieldPath, typeOfValue, flattener, platformConfig.asObject(JSONObject.EMPTY));

      if(value != null) {
        return value;
      }
    } catch(final NoSuchFieldException noSuchFieldInPlatform) {
      // ignore
    }
  }

  return walkPath(fieldPath, typeOfValue, flattener, genericConfig.asObject(JSONObject.EMPTY));
}
 
开发者ID:defrac,项目名称:defrac-plugin-intellij,代码行数:23,代码来源:DefracConfigOracle.java

示例13: walkPath

import defrac.json.JSON; //导入依赖的package包/类
@Nullable
private <A> A walkPath(@NotNull final String fieldPath,
                       @NotNull final Class<A> typeOfValue,
                       @NotNull final Function<JSON, A> flattener,
                       @NotNull final JSONObject config) throws NoSuchFieldException, IllegalAccessException {
  final Iterator<String> pathElements = PATH_SPLITTER.split(fieldPath).iterator();
  JSON current = config;

  while(pathElements.hasNext()) {
    final String pathElement = pathElements.next();

    if(current instanceof JSONObject) {
      final JSONObject obj = (JSONObject)current;

      if(!obj.contains(pathElement)) {
        return null;
      }

      current = obj.get(pathElement);
    } else {
      return null;
    }
  }

  return typeOfValue.cast(flattener.apply(current));
}
 
开发者ID:defrac,项目名称:defrac-plugin-intellij,代码行数:27,代码来源:DefracConfigOracle.java

示例14: decodeLayers

import defrac.json.JSON; //导入依赖的package包/类
@Nonnull
private static MapLayer[] decodeLayers( @Nonnull final JSONArray jsonArray )
{
	final MapLayer[] mapLayers = new MapLayer[ jsonArray.length() ];

	int index = 0;

	for( final JSON json : jsonArray )
		mapLayers[ index++ ] = decodeLayer( checkNotNull( json.asObject() ) );

	return mapLayers;
}
 
开发者ID:andremichelle,项目名称:platforms,代码行数:13,代码来源:MapResources.java

示例15: applyColor

import defrac.json.JSON; //导入依赖的package包/类
protected void applyColor(@Nonnull final LayoutContext context,
                          @Nonnull final JSONObject properties,
                          @Nonnull final Quad quad) {
  final JSON property = context.resolveProperty(properties, "color");

  if(null != property) {
    if(property.isString()) {
      quad.color(Color.valueOf(context.interpolateString(property.stringValue())));
    } else {
      quad.color(property.intValue());
    }
  }
}
 
开发者ID:defrac,项目名称:defrac-gaming,代码行数:14,代码来源:QuadInflater.java


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