Exemplo n.º 1
0
 public static String toJsonString(List<BaseMap> maps) throws JSONException {
   JSONArray array = new JSONArray();
   for (BaseMap map : maps) {
     array.put(map.toJson());
   }
   return array.toString();
 }
Exemplo n.º 2
0
  public static List<BaseMap> fromJsonString(String json) throws JSONException {
    List<BaseMap> maps = new ArrayList<>();
    if (json.length() == 0) return maps;
    JSONArray array = new JSONArray(json);

    for (int i = 0; i < array.length(); i++) {
      JSONObject jsonObject = array.getJSONObject(i);
      BaseMap map = new BaseMap();
      map.parentFolder = jsonObject.getString(PARENT_FOLDER);
      map.databasePath = jsonObject.getString(DATABASE_PATH);
      map.mapType = jsonObject.getString(MAP_TYPE);
      map.title = jsonObject.getString(TITLE);

      File databaseFile = new File(map.databasePath);
      if (databaseFile.exists()) {
        maps.add(map);
      }
    }
    return maps;
  }