本文整理了Java中com.badlogic.gdx.utils.Json.setWriter()
方法的一些代码示例,展示了Json.setWriter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.setWriter()
方法的具体详情如下:
包路径:com.badlogic.gdx.utils.Json
类名称:Json
方法名:setWriter
[英]Sets the writer where JSON output will be written. This is only necessary when not using the toJson methods.
[中]设置写入JSON输出的写入程序。这仅在不使用toJson方法时才有必要。
代码示例来源:origin: libgdx/libgdx
/** @param knownType May be null if the type is unknown.
* @param elementType May be null if the type is unknown. */
public void toJson (Object object, Class knownType, Class elementType, Writer writer) {
setWriter(writer);
try {
writeValue(object, knownType, elementType);
} finally {
StreamUtils.closeQuietly(this.writer);
this.writer = null;
}
}
代码示例来源:origin: libgdx/libgdx
/** @param knownType May be null if the type is unknown.
* @param elementType May be null if the type is unknown. */
public void toJson (Object object, Class knownType, Class elementType, Writer writer) {
setWriter(writer);
try {
writeValue(object, knownType, elementType);
} finally {
StreamUtils.closeQuietly(this.writer);
this.writer = null;
}
}
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
public void setAction(Action a) {
action = a;
Json json = new Json();
StringWriter buffer = new StringWriter();
json.setWriter(buffer);
ActionUtils.writeJson(a, json);
serializedAction = buffer.toString();
}
代码示例来源:origin: com.badlogicgames.gdx/gdx
/** @param knownType May be null if the type is unknown.
* @param elementType May be null if the type is unknown. */
public void toJson (Object object, Class knownType, Class elementType, Writer writer) {
setWriter(writer);
try {
writeValue(object, knownType, elementType);
} finally {
StreamUtils.closeQuietly(this.writer);
this.writer = null;
}
}
代码示例来源: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: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("level", level);
json.writeValue("removeGamma", removeGamma);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("level", level);
json.writeValue("iterations", iterations);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("level", level);
json.writeValue("threshold", threshold);
json.writeValue("dithering", dithering);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("encoding", encoding.name());
json.writeValue("quality", quality);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("encoding", encoding.name());
if (compression != null) {
json.writeValue("compType", compression.getType());
json.writeValue("compData", compression.serializeState());
}
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源:origin: crashinvaders/gdx-texture-packer-gui
@Override
public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("format", format.name());
json.writeValue("encodingEtc1", encodingEtc1.name());
json.writeValue("encodingEtc2", encodingEtc2.name());
json.writeValue("zipping", zipping);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}
代码示例来源: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: bladecoder/bladecoder-adventure-engine
public static Object cloneElement(Object e) {
Json json = new BladeJson(Ctx.project.getWorld(), Mode.MODEL);
if (e instanceof Action) {
StringWriter buffer = new StringWriter();
json.setWriter(buffer);
ActionUtils.writeJson((Action) e, json);
String str = buffer.toString();
EditorLogger.debug(str);
JsonValue root = new JsonReader().parse(str);
return ActionUtils.readJson(Ctx.project.getWorld(), json, root);
} else if (e instanceof Scene) {
String str = json.toJson(e, (Class<?>) null);
Scene s = new Scene(((Scene)e).getWorld());
JsonValue root = new JsonReader().parse(str);
s.read(json, root);
return s;
} else {
String str = json.toJson(e, (Class<?>) null);
return json.fromJson(e.getClass(), str);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!