本文整理了Java中com.badlogic.gdx.utils.Json.setOutputType()
方法的一些代码示例,展示了Json.setOutputType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.setOutputType()
方法的具体详情如下:
包路径:com.badlogic.gdx.utils.Json
类名称:Json
方法名:setOutputType
暂无
代码示例来源: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: org.mini2Dx/mini2Dx-core
/**
* Writes a JSON document by searching the object for
* {@link org.mini2Dx.core.serialization.annotation.Field} annotations
*
* @param object
* The object to convert to JSON
* @param prettyPrint
* Set to true if the JSON should be prettified
* @return The object serialized as JSON
* @throws SerializationException
* Thrown when the object is invalid
*/
public <T> String toJson(T object, boolean prettyPrint) throws SerializationException {
StringWriter writer = new StringWriter();
Json json = new Json();
json.setOutputType(OutputType.json);
json.setWriter(writer);
writeObject(null, object, null, json);
String result = writer.toString();
try {
writer.close();
} catch (IOException e) {
throw new SerializationException(e);
}
if (prettyPrint) {
return json.prettyPrint(result);
}
return result;
}
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
public void saveModel(String chapterId) throws IOException {
EngineLogger.debug("SAVING GAME MODEL");
if (w.isDisposed())
return;
Json json = new BladeJson(w, Mode.MODEL);
json.setOutputType(OutputType.javascript);
String s = null;
if (EngineLogger.debugMode())
s = json.prettyPrint(this);
else
s = json.toJson(this);
Writer w = EngineAssetManager.getInstance().getModelFile(chapterId + EngineAssetManager.CHAPTER_EXT)
.writer(false, "UTF-8");
try {
w.write(s);
w.flush();
} catch (IOException e) {
throw new IOException("ERROR SAVING MODEL", e);
} finally {
w.close();
}
}
代码示例来源:origin: de.golfgl.gdxgameanalytics/gdx-gameanalytics-core
json.setOutputType(JsonWriter.OutputType.json);
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
public void saveGameState(String filename, boolean screenshot) throws IOException {
EngineLogger.debug("SAVING GAME STATE");
if (w.isDisposed())
return;
Json json = new BladeJson(w, Mode.STATE);
json.setOutputType(OutputType.javascript);
String s = null;
if (EngineLogger.debugMode())
s = json.prettyPrint(this);
else
s = json.toJson(this);
Writer writer = EngineAssetManager.getInstance().getUserFile(filename).writer(false, "UTF-8");
try {
writer.write(s);
writer.flush();
} catch (IOException e) {
throw new IOException("ERROR SAVING GAME", e);
} finally {
writer.close();
}
// Save Screenshot
if (screenshot)
w.takeScreenshot(filename + ".png", SCREENSHOT_DEFAULT_WIDTH);
}
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
public void saveWorldDesc(FileHandle file) throws IOException {
float scale = EngineAssetManager.getInstance().getScale();
Json json = new BladeJson(w, Mode.MODEL);
json.setOutputType(OutputType.javascript);
json.setWriter(new StringWriter());
json.writeObjectStart();
json.writeValue("width", w.getWidth() / scale);
json.writeValue("height", w.getHeight() / scale);
json.writeValue("initChapter", w.getInitChapter());
w.getVerbManager().write(json);
json.writeObjectEnd();
String s = null;
if (EngineLogger.debugMode())
s = json.prettyPrint(json.getWriter().getWriter().toString());
else
s = json.getWriter().getWriter().toString();
Writer w = file.writer(false, "UTF-8");
w.write(s);
w.close();
}
代码示例来源:origin: de.golfgl.gdxgameanalytics/gdx-gameanalytics-core
json.setOutputType(JsonWriter.OutputType.json);
内容来源于网络,如有侵权,请联系作者删除!