本文整理了Java中com.badlogic.gdx.utils.Json.fromJson()
方法的一些代码示例,展示了Json.fromJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.fromJson()
方法的具体详情如下:
包路径:com.badlogic.gdx.utils.Json
类名称:Json
方法名:fromJson
暂无
代码示例来源:origin: libgdx/libgdx
private void check (String text, Object object) {
Object object2 = json.fromJson(object.getClass(), text);
equals(object, object2);
}
代码示例来源:origin: libgdx/libgdx
/** Adds all resources in the specified skin JSON file. */
public void load (FileHandle skinFile) {
try {
getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
} catch (SerializationException ex) {
throw new SerializationException("Error reading file: " + skinFile, ex);
}
}
代码示例来源:origin: libgdx/libgdx
/** Adds all resources in the specified skin JSON file. */
public void load (FileHandle skinFile) {
try {
getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
} catch (SerializationException ex) {
throw new SerializationException("Error reading file: " + skinFile, ex);
}
}
代码示例来源:origin: libgdx/libgdx
static public void main (String[] args) throws Exception {
Settings settings = null;
String input = null, output = null, packFileName = "pack.atlas";
switch (args.length) {
case 4:
settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
case 3:
packFileName = args[2];
case 2:
output = args[1];
case 1:
input = args[0];
break;
default:
System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
System.exit(0);
}
if (output == null) {
File inputFile = new File(input);
output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
}
if (settings == null) settings = new Settings();
process(settings, input, output, packFileName);
}
}
代码示例来源:origin: libgdx/libgdx
static public void main (String[] args) throws Exception {
Settings settings = null;
String input = null, output = null, packFileName = "pack.atlas";
switch (args.length) {
case 4:
settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
case 3:
packFileName = args[2];
case 2:
output = args[1];
case 1:
input = args[0];
break;
default:
System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
System.exit(0);
}
if (output == null) {
File inputFile = new File(input);
output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
}
if (settings == null) settings = new Settings();
process(settings, input, output, packFileName);
}
}
代码示例来源:origin: libgdx/libgdx
private void testObjectGraph (TestMapGraph object, String typeName) {
Json json = new Json();
json.setTypeName(typeName);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(OutputType.json);
String text = json.prettyPrint(object);
TestMapGraph object2 = json.fromJson(TestMapGraph.class, text);
if (object2.map.size() != object.map.size()) {
throw new RuntimeException("Too many items in deserialized json map.");
}
if (object2.objectMap.size != object.objectMap.size) {
throw new RuntimeException("Too many items in deserialized json object map.");
}
if (object2.arrayMap.size != object.arrayMap.size) {
throw new RuntimeException("Too many items in deserialized json map.");
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectLoadParameter parameter) {
Json json = new Json();
ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file);
Array<AssetData> assets = null;
synchronized (items) {
ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>();
entry.key = fileName;
entry.value = data;
items.add(entry);
assets = data.getAssets();
}
Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>();
for (AssetData<?> assetData : assets) {
// If the asset doesn't exist try to load it from loading effect directory
if (!resolve(assetData.filename).exists()) {
assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path();
}
if (assetData.type == ParticleEffect.class) {
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter));
} else
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type));
}
return descriptors;
}
代码示例来源:origin: libgdx/libgdx
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectLoadParameter parameter) {
Json json = new Json();
ResourceData<ParticleEffect> data = json.fromJson(ResourceData.class, file);
Array<AssetData> assets = null;
synchronized (items) {
ObjectMap.Entry<String, ResourceData<ParticleEffect>> entry = new ObjectMap.Entry<String, ResourceData<ParticleEffect>>();
entry.key = fileName;
entry.value = data;
items.add(entry);
assets = data.getAssets();
}
Array<AssetDescriptor> descriptors = new Array<AssetDescriptor>();
for (AssetData<?> assetData : assets) {
// If the asset doesn't exist try to load it from loading effect directory
if (!resolve(assetData.filename).exists()) {
assetData.filename = file.parent().child(Gdx.files.internal(assetData.filename).name()).path();
}
if (assetData.type == ParticleEffect.class) {
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type, parameter));
} else
descriptors.add(new AssetDescriptor(assetData.filename, assetData.type));
}
return descriptors;
}
代码示例来源:origin: libgdx/libgdx
Vector2 fromJson = json.fromJson(Vector2.class, jsonString);
println("JSON serialized: " + jsonString);
println("JSON deserialized: " + fromJson);
代码示例来源:origin: SquidPony/SquidLib
/**
* @param type May be null if the type is unknown.
* @param json
* @return May be null.
*/
@Override
public <T> T fromJson(Class<T> type, String json) {
return super.fromJson(type, LZSPlus.decompress(json));
}
代码示例来源:origin: SquidPony/SquidLib
/**
* @param type May be null if the type is unknown.
* @param elementType
* @param json
* @return May be null.
*/
@Override
public <T> T fromJson(Class<T> type, Class elementType, String json) {
return super.fromJson(type, elementType, LZSPlus.decompress(json));
}
}
代码示例来源:origin: com.badlogicgames.gdx/gdx
/** Adds all resources in the specified skin JSON file. */
public void load (FileHandle skinFile) {
try {
getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
} catch (SerializationException ex) {
throw new SerializationException("Error reading file: " + skinFile, ex);
}
}
代码示例来源:origin: kotcrab/vis-ui
public FileHandle loadLastDirectory () {
String data = prefs.getString(lastDirKeyName, null);
if (data == null) return null;
return json.fromJson(FileHandleData.class, data).toFileHandle();
}
代码示例来源:origin: SquidPony/SquidLib
/**
* @param type May be null if the type is unknown.
* @param file
* @return May be null.
*/
@Override
public <T> T fromJson(Class<T> type, FileHandle file) {
return super.fromJson(type, LZSPlus.decompress(file.readString("UTF-8")));
}
代码示例来源:origin: SquidPony/SquidLib
/**
* @param type May be null if the type is unknown.
* @param elementType May be null if the type is unknown.
* @param file
* @return May be null.
*/
@Override
public <T> T fromJson(Class<T> type, Class elementType, FileHandle file) {
return super.fromJson(type, elementType, LZSPlus.decompress(file.readString("UTF-8")));
}
代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-jam
private static AseFormat fromJson(FileHandle jsonFile) {
final Json json = new Json();
json.setIgnoreUnknownFields(true);
return json.fromJson(AseFormat.class, jsonFile);
}
代码示例来源:origin: kotcrab/vis-ui
public Array<FileHandle> loadRecentDirectories () {
String data = prefs.getString(recentDirKeyName, null);
if (data == null)
return new Array<FileHandle>();
else
return json.fromJson(FileArrayData.class, data).toFileHandleArray();
}
代码示例来源:origin: kotcrab/vis-ui
public Array<FileHandle> loadFavorites () {
String data = prefs.getString(favoritesKeyName, null);
if (data == null)
return new Array<FileHandle>();
else
return json.fromJson(FileArrayData.class, data).toFileHandleArray();
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Initiate(priority = AutumnActionPriority.TOP_PRIORITY) void init() {
modulesDir.mkdirs();
if (repoCacheFile.exists()) {
Array<RepositoryModuleData> newArray = json.fromJson(Array.class, RepositoryModuleData.class, repoCacheFile);
repositoryModules.clear();
for (RepositoryModuleData moduleData : newArray) {
repositoryModules.put(moduleData.name, moduleData);
}
Gdx.app.log(TAG, "Cached data was loaded");
}
requestRefreshRepositoryIfNeeded();
}
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public void read(Json json, JsonValue jsonData) {
try {
type = ClassReflection.forName(jsonData.get("type").asString());
} catch (Exception e) {
type = null;
}
path = jsonData.get("path").asString();
JsonValue parametersValue = jsonData.get("parameters");
parameters = parametersValue != null ? json.fromJson(AssetLoaderParameters.class, parametersValue.toString()) : null;
}
}
内容来源于网络,如有侵权,请联系作者删除!