Thread: Is this JSON?

Results 1 to 6 of 6
  1. #1 Is this JSON? 
    Registered Member

    Join Date
    Jan 2013
    Posts
    553
    Thanks given
    38
    Thanks received
    154
    Rep Power
    127
    Not too familiar with JSON, but really cba trying to hardcode all the definitions:

    Code:
    {"animations":{"death":836,"attack":422},"size":1,"lifepoints":150,"weakness":"Fire","id":1,"poisonous":false,"attackable":true,"magic":1,"level":6,"defence":3,"description":"One of RuneScape's many citizens.","name":"Man","ranged":1,"areas":["RuneScape Surface"],"attack":3,"aggressive":false,"members":false}
    Was going to try and do something like this to extract the information and then make my own binary file:

    Code:
    public static void init() throws IOException {
    		File folder = new File("./data/");
    		definitions = new NPCDefinition[16733];
    		for (File file : folder.listFiles()) {
    			int id = Integer.valueOf(file.getName().replace(".txt", ""));
    			NPCDefinition definition = new NPCDefinition();
    			definition.id = id;
    			BufferedReader reader = new BufferedReader(new FileReader(file));
    			String line = reader.readLine().toLowerCase();
    			if (line.contains("\"death\":")) {
    				String[] start = line.split("\"death\":");
    				String[] end = line.split(",\"attack\":");
    				String value = line.substring((line.length() - start[1].length()), end[0].length());
    				if (value.length() > 5) {
    					value = value.split("},\"size\":")[0];
    				}
    				if (value.length() <= 5) {
    					definition.deathAnimation = Integer.valueOf(value);
    				}
    			}
    			if (line.contains("\"attack\":")) {
    				try {
    					String[] start = line.split("\"attack\":");
    					String[] end = line.split("},\"size\":");
    					String value = line.substring(start[0].length() + 9, end[0].length());
    					if (value.length() > 5) {
    						value = value.split("},\"slayercat\":")[0];
    					}
    					if (value.length() > 5) {
    						value = value.split("},\"slayerlevel\":")[0];
    					}
    					if (value.length() <= 5) {
    						definition.attackAnimation = Integer.valueOf(value);
    					}
    				} catch (Exception exception) {}
    			}
    			
    		}
    	}
    But realized that it would take forever to get that to extract all the information perfectly and some definitions might not even be loaded correctly.

    My question is: is the definition (from the bestiary dump) written in JSON or does anyone know with what library I can easily read it?

    Note: Not all the files are the same: i.e this is another one:

    Code:
    {"animations":{"death":13772},"size":2,"lifepoints":500,"weakness":"None","id":9929,"poisonous":false,"attackable":true,"magic":1,"level":2,"defence":1,"description":"It's got a cold stare.","name":"Plane-freezer Lakhrahnaz","ranged":1,"areas":[],"attack":1,"aggressive":true,"members":false}
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Nov 2010
    Posts
    339
    Thanks given
    84
    Thanks received
    122
    Rep Power
    182
    yes that is JSON
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Jan 2013
    Posts
    553
    Thanks given
    38
    Thanks received
    154
    Rep Power
    127
    Any idea how to read it? I'm thinking GSON or something, but I've never really used JSON parsing, so not familiar with any of it.

    Main part I wouldn't really get is this:

    Code:
    {"animations":{"death":836,"attack":422}
    Animations would be a different class with the variables such as death, attack, ranged (yes some of them do have ranged instead of attack), etc, since I don't see how it would be an array (since some have different orders, such as "ranged":###,"death":###)
    Reply With Quote  
     

  4. #4  
    Father Of Lies


    Join Date
    May 2012
    Age
    26
    Posts
    1,216
    Thanks given
    267
    Thanks received
    289
    Rep Power
    242
    My question is: is the definition (from the bestiary dump) written in JSON

    Yes.
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Nov 2010
    Posts
    339
    Thanks given
    84
    Thanks received
    122
    Rep Power
    182
    took the time to make this for ya:
    http://www.rune-server.org/runescape...ml#post3901029
    Reply With Quote  
     

  6. #6  
    Registered Member

    Join Date
    Jan 2013
    Posts
    553
    Thanks given
    38
    Thanks received
    154
    Rep Power
    127
    Quote Originally Posted by Cyberus View Post
    Thanks, but already did it
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •