예제 #1
0
  @Override
  public void fromJSON(Object doc) {
    JSONDocument json = JSON.Parser.toJSON(doc);

    year = (int) json.getNumber("year");
    seaLevel = (double) json.getNumber("sea-level");

    List<Object> eventArray = json.get("events").array();
    for (int i = 0; i < eventArray.size(); i++) {
      SpecialEventData data = new SpecialEventData(null);
      data.fromJSON(eventArray.get(i));
      eventList.add(data);
    }

    List<Object> foodPriceArray = json.get("food-prices").array();
    for (int i = 0; i < foodPriceArray.size(); i++) {
      foodPrice[i] = (int) foodPriceArray.get(i);
    }

    List<Object> regionArray = json.get("regions").array();
    for (int i = 0; i < regionArray.size(); i++) {
      RegionData data = new RegionData(null);
      data.fromJSON(regionArray.get(i));
      regionData[i] = data;
    }
  }
 /**
  * Convert String into JSON
  *
  * @param doc object to be converted
  */
 @Override
 public void fromJSON(Object doc) {
   JSONDocument json = JSON.Parser.toJSON(doc);
   PACKED_CROP_RATINGS = new byte[json.getNumber("total_crop_tiles").intValue()];
   PACKED_TILE_COORDINATES = new int[json.getNumber("total_coord_tiles").intValue()];
   for (int i = 0; i < PACKED_CROP_RATINGS.length; i++) {
     PACKED_CROP_RATINGS[i] = json.getNumber("crop " + i).byteValue();
     if (i < PACKED_TILE_COORDINATES.length)
       PACKED_TILE_COORDINATES[i] = json.getNumber("coord " + i).intValue();
   }
 }