Esempio n. 1
0
 private void jsonToUsuario(JsonReader reader) throws JSONException, IOException {
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     switch (name) {
       case "id":
         this.id = reader.nextInt();
         break;
       case "token":
         this.token = reader.nextString();
         break;
       case "latitud":
         this.latitud = reader.nextDouble();
         break;
       case "longitud":
         this.longitud = reader.nextDouble();
         break;
       case "activo":
         this.activo = reader.nextBoolean();
         break;
       case "ofreceTransito":
         this.ofreceTransito = reader.nextBoolean();
         break;
       case "autopublicar":
         this.autopublicar = reader.nextBoolean();
         break;
       case "email":
         this.email = reader.nextString();
         break;
       case "username":
         this.username = reader.nextString();
         break;
       case "password":
         this.password = reader.nextString();
         break;
       case "telefono":
         this.telefono = reader.nextString();
         break;
       case "direccion":
         this.direccion = reader.nextString();
         break;
       case "foto":
         if (reader.peek() == JsonToken.NULL) reader.nextNull();
         else {
           this.foto = null;
           reader.nextString();
           // TODO: Completar cuando el post del usuario admita json
           // this.foto.setImg(Imagen.bytesFromBase64DEFAULT(reader.nextString()));
         }
         break;
       default:
         reader.skipValue();
         break;
     }
   }
   reader.endObject();
 }
 /** Peeks at the next token and returns a {@link Boolean} or {@code null} */
 Boolean nextBooleanOrNull() throws IOException {
   if (_reader.peek() == JsonToken.NULL) {
     _reader.nextNull();
     return null;
   }
   return _reader.nextBoolean();
 }
Esempio n. 3
0
  public Repo readMessage(JsonReader reader) throws IOException {

    repo = new Repo();

    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();

      if (name.equals("name")) {
        repo.setName(reader.nextString());
      } else if (name.equals("description")) {
        repo.setDescription(reader.nextString());
      } else if (name.equals("owner")) {
        ReadOwnerMessage(reader);
      } else if (name.equals("html_url")) {
        repo.setRepo_url(reader.nextString());
      } else if (name.equals("fork")) {
        repo.setFork(reader.nextBoolean());
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();
    return repo;
  }
Esempio n. 4
0
 @SuppressWarnings("cast")
 public static some.test.Booleans createUsingJsonStream(Realm realm, JsonReader reader)
     throws IOException {
   some.test.Booleans obj = realm.createObject(some.test.Booleans.class);
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("done")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException("Trying to set non-nullable field 'done' to null.");
       } else {
         ((BooleansRealmProxyInterface) obj).realmSet$done((boolean) reader.nextBoolean());
       }
     } else if (name.equals("isReady")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException("Trying to set non-nullable field 'isReady' to null.");
       } else {
         ((BooleansRealmProxyInterface) obj).realmSet$isReady((boolean) reader.nextBoolean());
       }
     } else if (name.equals("mCompleted")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException(
             "Trying to set non-nullable field 'mCompleted' to null.");
       } else {
         ((BooleansRealmProxyInterface) obj).realmSet$mCompleted((boolean) reader.nextBoolean());
       }
     } else if (name.equals("anotherBoolean")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException(
             "Trying to set non-nullable field 'anotherBoolean' to null.");
       } else {
         ((BooleansRealmProxyInterface) obj)
             .realmSet$anotherBoolean((boolean) reader.nextBoolean());
       }
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return obj;
 }
Esempio n. 5
0
  public static void read() {
    String filename = String.format(getRootDir() + "/conf.json");
    try {
      FileInputStream fin = new FileInputStream(filename);
      JsonReader reader = new JsonReader(new InputStreamReader(fin, "UTF-8"));

      reader.beginObject();

      // write common information
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("LENGTH_UNIT")) {
          LENGTH_UNIT = reader.nextString();
        } else if (name.equals("MAP_TYPE")) {
          MAP_TYPE = reader.nextString();
        } else if (name.equals("SPEED_TYPE")) {
          SPEED_TYPE = reader.nextString();
        } else if (name.equals("MIN_DISTANCE")) {
          MIN_DISTANCE = reader.nextInt();
        } else if (name.equals("INTERVAL_LOCATION")) {
          INTERVAL_LOCATION = reader.nextInt();
        } else if (name.equals("INTERVAL_LOCATION_FAST")) {
          INTERVAL_LOCATION_FAST = reader.nextInt();
        } else if (name.equals("LOCATION_ACCURACY")) {
          LOCATION_ACCURACY = reader.nextInt();
        } else if (name.equals("SPEED_AVG")) {
          SPEED_AVG = reader.nextInt();
        } else if (name.equals("GPS_ONLY")) {
          GPS_ONLY = reader.nextBoolean();
        } else if (name.equals("GPS_ONLY")) {
          ACCELERATE_FACTOR = (float) reader.nextDouble();
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();

      reader.close();
      fin.close();
    } catch (Exception e) {
      Log.i(TAG, "read conf from file fail.");
    }
  }