我不知道问题是什么;
[13-11-13 19:28]: Unexpected character (A) at position 32480.
[13-11-13 19:28]: Succesfully loaded 0 item definitions!
[13-11-13 19:28]: at org.json.simple.parser.Yylex.yylex(Yylex.java:610)
[13-11-13 19:28]: at org.json.simple.parser.JSONParser.nextToken(JSONParser.java:269)
[13-11-13 19:28]: at org.json.simple.parser.JSONParser.parse(JSONParser.java:118)
[13-11-13 19:28]: at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)
[13-11-13 19:28]: at server.world.ItemHandler.initItemDefs(ItemHandler.java:375)
[13-11-13 19:28]: at server.world.ItemHandler.<init>(ItemHandler.java:37)
[13-11-13 19:28]: at server.GameServer.<clinit>(GameServer.java:68)
[13-11-13 19:28]: at server.Engine.main(Engine.java:18)
重定向到这一行:
JSONArray input = (JSONArray) JSONReader.PARSER.parse(new FileReader(FileName));
在这种方法中:
public void initItemDefs(String FileName) {
int itemAmount = 0;
try {
JSONArray input = (JSONArray) JSONReader.PARSER.parse(new FileReader(FileName));
for (Object o : input) {
JSONObject config = (JSONObject) o;
try {
if (config.get("item-id") != null) {
int itemId = Integer.parseInt(config.get("item-id").toString());
String itemName = config.get("item-name").toString();
String itemExamine = config.get("item-examine").toString();
double shopvalue = Double.parseDouble(config.get("shop-value").toString());
double lowalch = Double.parseDouble(config.get("low-alch").toString());
double highalch = Double.parseDouble(config.get("high-alch").toString());
int stabBonus = Integer.parseInt(config.get("stab-bonus").toString());
int slashBonus = Integer.parseInt(config.get("slash-bonus").toString());
int crushBonus = Integer.parseInt(config.get("crush-bonus").toString());
int magicBonus = Integer.parseInt(config.get("magic-bonus").toString());
int rangedBonus = Integer.parseInt(config.get("ranged-bonus").toString());
int stabDefence = Integer.parseInt(config.get("stab-defence").toString());
int slashDefence = Integer.parseInt(config.get("slash-defence").toString());
int crushDefence = Integer.parseInt(config.get("crush-defence").toString());
int magicDefence = Integer.parseInt(config.get("magic-defence").toString());
int rangedDefence = Integer.parseInt(config.get("ranged-defence").toString());
int strengthBonus = Integer.parseInt(config.get("strength-bonus").toString());
int prayerBonus = Integer.parseInt(config.get("prayer-bonus").toString());
newItemList(itemId, itemName, itemExamine, shopvalue, lowalch, highalch, new int [] {stabBonus, slashBonus, crushBonus, magicBonus, rangedBonus, stabDefence, slashDefence, crushDefence, magicDefence, rangedDefence, strengthBonus, prayerBonus});
itemAmount++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("Succesfully loaded " +itemAmount+ " item definitions!");
}
文件格式如下:
[{
"item-id" : "0",
"item-name" : "Dwarf remains",
"item-examine" : "The body of a Dwarf savaged by Goblins.",
"shop-value" : "0.0",
"low-alch" : "0.0",
"high-alch" : "0.0",
"stab-bonus" : "0",
"slash-bonus" : "0",
"crush-bonus" : "0",
"magic-bonus" : "0",
"ranged-bonus" : "0",
"stab-defence" : "0",
"slash-defence" : "0",
"crush-defence" : "0",
"magic-defence" : "0",
"ranged-defence" : "0",
"strength-bonus" : "0",
"prayer-bonus" : "0",
},
{
"item-id" : "1",
"item-name" : "Toolkit",
"item-examine" : "Good for repairing a broken cannon.",
"shop-value" : "0.0",
"low-alch" : "0.0",
"high-alch" : "0.0",
"stab-bonus" : "0",
"slash-bonus" : "0",
"crush-bonus" : "0",
"magic-bonus" : "0",
"ranged-bonus" : "0",
"stab-defence" : "0",
"slash-defence" : "0",
"crush-defence" : "0",
"magic-defence" : "0",
"ranged-defence" : "0",
"strength-bonus" : "0",
"prayer-bonus" : "0",
}]
然后是25k条目。