本文整理汇总了Java中com.badlogic.gdx.utils.Json.toJson方法的典型用法代码示例。如果您正苦于以下问题:Java Json.toJson方法的具体用法?Java Json.toJson怎么用?Java Json.toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.Json
的用法示例。
在下文中一共展示了Json.toJson方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dataToString
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/**
* Returns JSON string representation of object.
* <p>
* It using libgdx {@link Json} class.
*
* @param object Any object
* @return JSON string representation of {@code object}
*/
public static String dataToString(Object object)
{
if (isPrimitiveType(object))
return object.toString();
Json json = new Json();
json.setTypeName(null);
json.setQuoteLongValues(true);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
return json.toJson(object);
}
示例2: mapToJSON
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/**
* @param map Map, not null
* @return JSON representation of given map
*/
public static String mapToJSON(Map<String, Object> map)
{
Json json = new Json();
json.setTypeName(null);
json.setQuoteLongValues(true);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
return json.toJson(map, HashMap.class);
}
示例3: modify
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/**
* Returns modified json data.
*
* @param oldJsonData Old data as json string.
* @return New data as json string
*/
public String modify(String oldJsonData)
{
R oldData = JsonProcessor.process(wantedType, transactionCallback, oldJsonData);
R newData = transactionCallback.run(oldData);
Json json = new Json();
json.setTypeName(null);
json.setQuoteLongValues(true);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
return json.toJson(newData, wantedType);
}
示例4: 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;
}
示例5: saveScene
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public void saveScene(String path) {
Json json = new Json();
json.toJson(scene, Gdx.files.absolute(path));
}
示例6: makePrefab
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
/** Makes a String describing the GameObject, usable to create a Prefab
*
* @param object - the GameObject that should be Serialized
* @return the String describing the Prefab */
public static String makePrefab (GameObject object) {
Json json = new Json();
json.setOutputType(OutputType.json);
String temp = json.toJson(object);
int transformStart = ordinalIndexOf(temp, '{', 1);
int firstComponentStart = ordinalIndexOf(temp, '{', 2);
String finalstring = temp.substring(0, transformStart) + temp.substring(firstComponentStart);
return finalstring;
}
示例7: toJson
import com.badlogic.gdx.utils.Json; //导入方法依赖的package包/类
public String toJson()
{
Json j = new Json();
j.setOutputType(OutputType.json);
j.setUsePrototypes(false);
j.setElementType(CGCStats.class, "allGames", CGCStatGame.class);
return j.toJson(this);
}