Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mp.gw2api.data; import com.mp.gw2api.lists.GW2APIMapList; import com.mp.gw2api.base.IGW2APIData; import com.mp.gw2api.base.PointRectangle; import com.mp.gw2api.base.GW2APIID; import com.mp.gw2api.base.GW2APIID; import com.mp.gw2api.base.IGW2APIData; import com.mp.gw2api.base.PointRectangle; import com.mp.gw2api.base.GW2APIMapContinent; import com.mp.gw2api.base.GW2APIMapRegion; import java.util.logging.Level; import java.util.logging.Logger; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; /** * * @author Mitchell Pell */ public class GW2APIMap extends GW2APIID implements IGW2APIData { //public long id; /*! Maps ID */ //public String name; /*! Maps Name */ public long minLevel; /*! */ public long maxLevel; /*! */ public long defFloor; /*! */ public long[] floors; /*! */ public GW2APIMapRegion region; /*! */ public GW2APIMapContinent continent; /*! */ public PointRectangle mapRect; public PointRectangle contRect; /*! Load the map list from Json Text */ @Override public void LoadFromJsonText(String text) { JSONParser parser = new JSONParser(); JSONObject json = null; JSONArray ja = null; JSONArray jb = null; try { //Parse json array json = (JSONObject) parser.parse(text); id = (long) json.get("id"); name = (String) json.get("name"); minLevel = (long) json.get("min_level"); maxLevel = (long) json.get("max_level"); defFloor = (long) json.get("default_floor"); ja = (JSONArray) json.get("floors"); if (ja != null) if (ja.size() > 0) { floors = new long[ja.size()]; for (int i = 0; i < ja.size(); i++) floors[i] = (long) ja.get(i); } region = new GW2APIMapRegion((long) json.get("region_id"), (String) json.get("region_name")); continent = new GW2APIMapContinent((long) json.get("continent_id"), (String) json.get("continent_name")); mapRect = new PointRectangle(); ja = (JSONArray) json.get("map_rect"); jb = (JSONArray) ja.get(0); mapRect.begin.x = (long) jb.get(0); mapRect.begin.y = (long) jb.get(1); jb = (JSONArray) ja.get(1); mapRect.end.x = (long) jb.get(0); mapRect.end.y = (long) jb.get(1); contRect = new PointRectangle(); ja = (JSONArray) json.get("continent_rect"); jb = (JSONArray) ja.get(0); contRect.begin.x = (long) jb.get(0); contRect.begin.y = (long) jb.get(1); jb = (JSONArray) ja.get(1); contRect.end.x = (long) jb.get(0); contRect.end.y = (long) jb.get(1); } catch (ParseException ex) { Logger.getLogger(GW2APIMapList.class.getName()).log(Level.SEVERE, null, ex); } } }