【发布时间】:2014-06-19 22:13:45
【问题描述】:
我有一个名为 item 的类,其中我有更多的整数和浮点字段,用于属性,如损坏、级别要求和其他内容。我想将一些预定义的项目保留在 json 文件中,当我需要一个具有该组属性的新项目时,可以使用 json 文件中的名称将其取出。假设我想要一把剑和一把弓:
//json example file -- this isn't a proper file
//this is a preview of what I would like
{
godly_sword {damage: 45, level: 10},
normal_bow {damage: 4, level: 3}
}
我希望能够通过名称从 json 中获取这些,并创建一个具有以下属性的新对象:
//Creating a new item which has a preset of attributes assigned to the name godly_sword
Item weapon = json.fromJson(Item.class, "godly_sword");
我尝试以不同的方式玩这个,但我所能做的就是只加载一个预设:
//Proper json file
{
class: game.Item,
damage: 45,
level: 10
}
这可行,但帮助不大,因为我不想为我预定义的每个项目创建一个 json 文件。任何建议都会很有帮助。
【问题讨论】:
标签: json libgdx filehandle