本文整理汇总了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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}