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


Java Json.fromJson方法代码示例

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


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

示例1: process

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/**
 * Converts json string into java object.
 *
 * @param wantedType        Wanted type
 * @param genericTypeKeeper Object with wanted type inside generic argument
 * @param jsonString        Json string data
 * @param <R>               Return type
 * @return
 */
public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString)
{
    Json json = new Json();
    json.setIgnoreUnknownFields(true);
    json.setTypeName(null);
    R result = null;
    if (ClassReflection.isAssignableFrom(List.class, wantedType)
            || ClassReflection.isAssignableFrom(Map.class, wantedType)) {
        NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper);
        if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException();
        json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value()));
        result = (R) json.fromJson(wantedType, jsonString);
    } else {
        result = (R) json.fromJson(wantedType, jsonString);
    }
    return result;
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:27,代码来源:JsonProcessor.java

示例2: loadPrevStats

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public void loadPrevStats()
{
	String loadedData = ChaseApp.fileHandler.readFile("stats.bin");

	if (!loadedData.equals(""))
	{
		Json json = new Json();
		CGCStats newStats = json.fromJson(CGCStats.class, loadedData);
		
		for (int i = 0; i < newStats.allGames.size; i++)
		{
			allGames.add(new CGCStatGame(newStats.allGames.get(i)));
		}
	}
	
	curGame = allGames.size;
}
 
开发者ID:ChainGangChase,项目名称:cgc-game,代码行数:18,代码来源:CGCStats.java

示例3: load

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public static void load(String mdata)
{
	if (!loaded) {
		try  
	    { 
	      mdata = "{\""+mdata.substring(mdata.indexOf("class")); 
	      mdata = mdata.replace("\t", ""); 
	       
	      Json json = new Json(); 
	      maps = json.fromJson(MapsVO.class, mdata); 
	      loaded = true;
	    } 
	    catch (Exception e) 
	    { 
	      Gdx.app.log("MapsResponder", "An error occurred with json"); 
	      Gdx.app.log("Error", e.getMessage()); 
	      maps = null; 
	    } 
	}
}
 
开发者ID:ChainGangChase,项目名称:cgc-game,代码行数:21,代码来源:MapData.java

示例4: loadLevelPacks

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
private static ArrayList<LevelPack> loadLevelPacks()
{
    Json json = new Json();

    String levelPacksString = Gdx.files.internal("level/levelPacks.json").readString();

    @SuppressWarnings("unchecked")
    ArrayList<String> serialisableLevelPackPaths = json.fromJson(
        ArrayList.class,
        String.class,
        levelPacksString);

    ArrayList<LevelPack> levelPacks = new ArrayList<>(serialisableLevelPackPaths.size());

    for (String serialisableLevelPackPath : serialisableLevelPackPaths)
    {
        LevelPack levelPack = loadLevelPack(serialisableLevelPackPath);
        levelPacks.add(levelPack);
    }

    return levelPacks;
}
 
开发者ID:overengineering,项目名称:space-travels-3,代码行数:23,代码来源:LevelManager.java

示例5: Story

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public Story (Assets assets){
    Json json = new Json();
    Board.Parameters[] params = json.fromJson(Board.Parameters[].class, Gdx.files.internal("boardParams.json"));
    for (int i = 0; i < params.length; i++) {
        Board.Parameters stageParams = params[i];
        Board board = new Board(assets, stageParams);
        boards.add(board);
    }

    movesPerTurn = 3;
    livesLeft = 3;
    heartsLeft = 3;
    stagesComplete = 0;
    stepsTaken = 0;
    enemiesDestroyed = 0;
}
 
开发者ID:cypherdare,项目名称:SpaceShift,代码行数:17,代码来源:Story.java

示例6: readReplayData

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/**
 * コースリプレイデータを読み込む
 * 
 * @param hash
 *            対象のBMSハッシュ群
 * @param lnmode
 *            LNモード
 * @return リプレイデータ
 */
public ReplayData[] readReplayData(String[] hash, boolean ln, int lnmode, int index,
		CourseData.CourseDataConstraint[] constraint) {
	if (existsReplayData(hash, ln, lnmode, index, constraint)) {
		Json json = new Json();
		json.setIgnoreUnknownFields(true);
		try {
			String path = this.getReplayDataFilePath(hash, ln, lnmode, index, constraint);
			if (Files.exists(Paths.get(path + ".brd"))) {
				return json.fromJson(ReplayData[].class, new BufferedInputStream(
						new GZIPInputStream(Files.newInputStream(Paths.get(path + ".brd")))));
			}
			if (Files.exists(Paths.get(path + ".json"))) {
				return json.fromJson(ReplayData[].class, new FileReader(path + ".json"));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
开发者ID:exch-bms2,项目名称:beatoraja,代码行数:30,代码来源:PlayDataAccessor.java

示例7: reload

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void reload () {
	RavTech.files.loadAsset("keybindings.json", String.class);
	RavTech.files.finishLoading();
	
	if ((!RavTech.settings.has("keybindings")))
		RavTech.settings.setValue("keybindings", RavTech.files.getAsset("keybindings.json", String.class));
	this.actionMaps.clear();
	Json json = new Json();

	ObjectMap<String, JsonValue> serializedActionMaps = json.fromJson(ObjectMap.class,
		RavTech.settings.getString("keybindings"));
	for (ObjectMap.Entry<String, JsonValue> entry : serializedActionMaps.entries()) {
		ActionMap actionMap = new ActionMap();
		actionMap.read(json, entry.value);
		this.actionMaps.put(entry.key, actionMap);
	}
	this.actionMaps.putAll(actionMaps);

	this.players.clear();
	Player player = new Player();
	for (int i = 0; i < inputDevices.size; i++)
		player.assignDevice(inputDevices.get(i), this.getActionMapForDevice(inputDevices.get(i)));
	players.add(player);
}
 
开发者ID:Quexten,项目名称:RavTech,代码行数:26,代码来源:RavInput.java

示例8: loadSprites

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
private void loadSprites() {
    final Json json = new Json();
    spriteLibrary = json.fromJson(SpriteLibrary.class, Gdx.files.internal("sprites.json"));
    for (SpriteData sprite : spriteLibrary.sprites) {
        Animation animation = add(sprite.id, sprite.x, sprite.y, sprite.width, sprite.height, sprite.countX, sprite.countY, this.tileset, sprite.milliseconds * 0.001f);
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-artax,代码行数:8,代码来源:GameScreenAssetSystem.java

示例9: toNSDictionary

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static NSDictionary toNSDictionary(Object object)
{
    if (object instanceof Map) {
        return toNSDictionary((Map) object);
    } else {
        String objectJsonData = new Json().toJson(object);
        Json json = new Json();
        json.setIgnoreUnknownFields(true);
        Map objectMap = json.fromJson(HashMap.class, objectJsonData);
        return toNSDictionary(objectMap);
    }
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:14,代码来源:NSDictionaryHelper.java

示例10: loadSprites

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
private void loadSprites() {
    final Json json = new Json();
    spriteLibrary = json.fromJson(SpriteLibrary.class, Gdx.files.internal("sprites.json"));
    for (SpriteData sprite : spriteLibrary.sprites) {
        add(sprite.id, sprite.x, sprite.y, sprite.width, sprite.height, sprite.countX, sprite.countY);
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:8,代码来源:GameScreenAssetSystem.java

示例11: loadPlanets

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
private void loadPlanets() {
    final Json json = new Json();
    planetLibrary = json.fromJson(PlanetLibrary.class, Gdx.files.internal("planets.json"));

    net.mostlyoriginal.game.component.PlanetData planet = planetLibrary.planets[1];
    {

        planetEntity = E.E();
        Planet planetE = planetEntity
                .renderLayer(G.LAYER_PLANET)
                .planet()
                .tag("planet")
                .pos(0, 0)
                .getPlanet();

        planetE.data = planet;

        for (net.mostlyoriginal.game.component.PlanetData.CellType type : planet.types) {
            Color color = Color.valueOf(type.color);
            Color colorArid = type.colorSecondary != null ? Color.valueOf(type.colorSecondary) : color;
            planetE.cellColor[type.type.ordinal()] = type.intColor = Color.rgba8888(color);
            planetE.cellColorSecondary[type.type.ordinal()] = type.intColorSecondary = Color.rgba8888(colorArid);
        }

        populate(planet, planetE);
        gravity(planetE);
        height(planetE);
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-little-fortune-planet,代码行数:30,代码来源:PlanetCreationSystem.java

示例12: handleHttpResponse

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
    String result = httpResponse.getResultAsString();

    Json json = new Json();

    ArrayList list = json.fromJson(ArrayList.class, result);
    Array<LeaderBoardEntry> leaderBoardEntries = new Array<LeaderBoardEntry>();

    if (list != null) {
        for (Object entry : list) {
            if (entry != null && entry instanceof JsonValue) {
                JsonValue jsonEntry = (JsonValue) entry;

                // the reflection does not seem to work on iOS
                // LeaderBoardEntry leaderBoardEntry = json.readValue(
                //    LeaderBoardEntry.class, (JsonValue)entry);
                LeaderBoardEntry leaderBoardEntry = new LeaderBoardEntry();
                try {
                    leaderBoardEntry.name = jsonEntry.getString("name");
                    leaderBoardEntry.rank = jsonEntry.getInt("rank");
                    leaderBoardEntry.score = jsonEntry.getInt("score");
                } catch (IllegalArgumentException e) {
                    Gdx.app.log(TAG, "failed to read json: " + e.toString());
                    return;
                }

                leaderBoardEntries.add(leaderBoardEntry);
            }
        }
    }

    mListener.onSuccess(leaderBoardEntries);
}
 
开发者ID:tgobbens,项目名称:fluffybalance,代码行数:35,代码来源:LeaderBoardController.java

示例13: instantiateGameObject

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
@Override
public JGameObjectImpl instantiateGameObject(JGameObject gameObject, Vector2 position) {
	JGameObjectImpl fullObject = (JGameObjectImpl) gameObject;
	Json json = JsonSceneSerializer.json;
	proxyGameObject(gameObject);
	String gameObjectJson = json.toJson(gameObject);
	unproxyGameObject(gameObject);

	JGameObjectImpl newObject = json.fromJson(JGameObjectImpl.class, gameObjectJson);
	unproxyGameObject(newObject);

	Transform transform = newObject.getComponent(Transform.class);
	newObject.setTransform(transform);
	if (fullObject.isPrefab())
		transform.setParent(null);
	transform.setPosition(position);

	// TODO move to next frame?
	if (run) {
		awakeGameObject(newObject);
	}

	gameObjects.add(newObject);

	if (run) {
		startGameObject(newObject);
		enableGameObject(newObject);
	}
	return newObject;
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:31,代码来源:CustomScene.java

示例14: texturePack

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
@Override
public void texturePack(Array<FileHandle> handles, FileHandle localFile, FileHandle targetFile) {
    //copy defaults.json to temp folder if it doesn't exist
    FileHandle fileHandle = Gdx.files.local("texturepacker/defaults.json");
    if (!fileHandle.exists()) {
        Gdx.files.internal("defaults.json").copyTo(fileHandle);
    }
    
    Json json = new Json();
    Settings settings = json.fromJson(Settings.class, fileHandle);
    
    TexturePacker p = new TexturePacker(settings);
    for (FileHandle handle : handles) {
        if (handle.exists()) {
            p.addImage(handle.file());
        } else {
            if (localFile != null) {
                FileHandle localHandle = localFile.sibling(localFile.nameWithoutExtension() + "_data/" + handle.name());
                if (localHandle.exists()) {
                    p.addImage(localHandle.file());
                } else {
                    Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
                }
            } else {
                Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
            }
        }
    }
    p.pack(targetFile.parent().file(), targetFile.nameWithoutExtension());
}
 
开发者ID:raeleus,项目名称:skin-composer,代码行数:31,代码来源:DesktopLauncher.java

示例15: load

import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public void load(FileHandle file) {
    Json json = new Json(JsonWriter.OutputType.minimal);
    ProjectData instance = json.fromJson(ProjectData.class, file.reader("UTF8"));
    newProject = instance.newProject;
    jsonData.set(instance.jsonData);
    atlasData.set(instance.atlasData);
    preferences.clear();
    preferences.putAll(instance.preferences);
    
    //set main for custom classes, styles, and properties
    for (CustomClass customClass : jsonData.getCustomClasses()) {
        customClass.setMain(main);
    }
    
    saveFile = file;
    putRecentFile(file.path());
    setLastOpenSavePath(file.parent().path() + "/");
    atlasData.atlasCurrent = false;
    
    correctFilePaths();
    
    if (verifyDrawablePaths().size == 0 && verifyFontPaths().size == 0) {
        main.getRootTable().produceAtlas();
        main.getRootTable().populate();
    }
    setChangesSaved(true);
}
 
开发者ID:raeleus,项目名称:skin-composer,代码行数:28,代码来源:ProjectData.java


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