Пример #1
1
 /** Peeks at the next token and returns a {@link Double} or {@code null} */
 Double nextNumberOrNull() throws IOException {
   if (_reader.peek() == JsonToken.NULL) {
     _reader.nextNull();
     return null;
   }
   return _reader.nextDouble();
 }
Пример #2
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();
 }
Пример #3
0
  @Override
  public void deSerializeRepresentation(JsonReader sreader) throws IOException {
    sreader.beginObject();
    Vector<StrokeData> strokes = new Vector<StrokeData>();

    while (sreader.hasNext()) {
      sreader.nextName();
      sreader.beginObject();
      StrokeData stroke = new StrokeData();

      while (sreader.hasNext()) {
        String name = sreader.nextName();
        if (name.equals(SERIAL_COLOR)) {
          stroke.mColor = sreader.nextInt();
        } else if (name.equals(SERIAL_RADIUS)) {
          stroke.mRadius = (float) sreader.nextDouble();
        } else if (name.equals(SERIAL_TYPE)) {
          stroke.mType = (byte) sreader.nextInt();
        } else if (name.equals(SERIAL_POINTS_COUNT)) {
          stroke.noPoints = sreader.nextInt();
        } else if (name.equals(SERIAL_POINTS)) {

          int count = 0;
          sreader.beginArray();
          while (sreader.hasNext()) {
            if ((count + 1) > stroke.mPoints.length) {
              stroke.mPoints = Arrays.copyOf(stroke.mPoints, count * 2);
            }
            stroke.mPoints[count++] = (float) sreader.nextDouble();
          }
          stroke.mPath = new Path();
          stroke.mPath.moveTo(stroke.mPoints[0], stroke.mPoints[1]);
          for (int i = 0; i < count; i += 2) {
            stroke.mPath.lineTo(stroke.mPoints[i], stroke.mPoints[i + 1]);
          }
          sreader.endArray();
          strokes.add(stroke);
        } else {
          sreader.skipValue();
        }
      }
      sreader.endObject();
    }

    mDrawing = strokes;

    sreader.endObject();
  }
Пример #4
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public Song parseSong(JsonReader jsonReader) {
    Song song = new Song();

    try {
      jsonReader.beginObject();
      while (jsonReader.hasNext()) {
        String name = jsonReader.nextName();
        if (name.equals(JSON_KEY_TRACKID)) {
          song.setId(jsonReader.nextLong());
        } else if (name.equals(JSON_KEY_ARTISTNAME)) {
          song.setArtist(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_TRACKNAME)) {
          song.setTitle(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_TRACKPRICE)) {
          song.setPrice(jsonReader.nextDouble());
        } else if (name.equals(JSON_KEY_TRACKCOVER)) {
          song.setCoverURL(jsonReader.nextString());
        } else {
          jsonReader.skipValue();
        }
      }
      jsonReader.endObject();

    } catch (IOException e) {
    }

    return song;
  }
Пример #5
0
    private FoodResult readHitObject(JsonReader reader) throws IOException {
      FoodResult food = new FoodResult();

      reader.beginObject();
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("_index")) {
          String index = reader.nextString();
          // we currently do nothing with this value
        } else if (name.equals("_type")) {
          String type = reader.nextString();
          // we currently do nothing with this value
        } else if (name.equals("_id")) {
          food.id = reader.nextString();
        } else if (name.equals("_score")) {
          double score = reader.nextDouble();
          // we currently do nothing with this value
        } else if (name.equals("fields")) {
          readHitFields(reader, food);
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();
      return food;
    }
Пример #6
0
 private void readGeometry(JsonReader reader) throws IOException {
   String s;
   reader.beginObject();
   while (reader.hasNext()) {
     s = reader.nextName();
     if (s.equals("coordinates")) {
       reader.beginArray();
       location = new Location("http://earthquake.usgs.gov/");
       location.setLongitude(reader.nextDouble());
       location.setLatitude(reader.nextDouble());
       location.setAltitude(-reader.nextDouble());
       reader.endArray();
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
 }
  private LatLng readLatLngPoint(JsonReader reader) throws IOException {

    Double lat = 33.690;
    Double ln = -117.9257;

    reader.beginObject();
    while (reader.hasNext()) {
      tag = reader.nextName();
      if (tag.equals("lat")) {
        lat = reader.nextDouble();
      } else if (tag.equals("ln")) {
        ln = reader.nextDouble();
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();
    return new LatLng(lat, ln);
  }
 private void parseWeatherFormWind(JsonReader reader) throws IOException {
   Log.d(TAG, "Entering parseWeatherFormWind");
   reader.beginObject();
   try {
     while (reader.hasNext()) {
       String name = reader.nextName();
       switch (name) {
         case JsonWeatherTokens.SPEED:
           weatherData.setSpeed(reader.nextDouble());
           break;
         case JsonWeatherTokens.DEG:
           weatherData.setDeg(reader.nextDouble());
           break;
         default:
           reader.skipValue();
           break;
       }
     }
   } finally {
     reader.endObject();
   }
 }
Пример #9
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.");
    }
  }
Пример #10
0
 private void readProperties(JsonReader reader) throws IOException {
   String s;
   reader.beginObject();
   while (reader.hasNext()) {
     s = reader.nextName();
     if (s.equals("mag")) {
       magnitude = reader.nextDouble();
     } else if (s.equals("place")) {
       details = reader.nextString();
     } else if (s.equals("detail")) {
       link = reader.nextString();
     } else if (s.equals("time")) {
       date = new Date(Long.parseLong(reader.nextString()));
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
 }
Пример #11
0
 private SearchResults readResults(JsonReader reader) throws IOException {
   SearchResults results = new SearchResults();
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("total_hits")) {
       results.count = reader.nextInt();
       if (results.count == 0) {
         return results;
       }
     } else if (name.equals("max_score")) {
       double max_score = reader.nextDouble();
       // we currently do nothing with this value
     } else if (name.equals("hits")) {
       results.list = readHitsArray(reader);
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return results;
 }
  private void parseWeatherFormMain(JsonReader reader) throws IOException {
    Log.d(TAG, "Entering parseWeatherFormMain");

    reader.beginObject();
    try {
      while (reader.hasNext()) {
        String name = reader.nextName();
        switch (name) {
          case JsonWeatherTokens.TEMP:
            weatherData.setTemp(reader.nextDouble());
            break;
          case JsonWeatherTokens.HUMIDITY:
            weatherData.setHumidity(reader.nextLong());
            break;
          default:
            reader.skipValue();
            break;
        }
      }
    } finally {
      reader.endObject();
    }
  }
Пример #13
0
 private void readHitFields(JsonReader reader, FoodResult food) throws IOException {
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("item_id")) {
       String id = reader.nextString();
       // we already saved the ID of this food
     } else if (name.equals("item_name")) {
       food.name = reader.nextString();
     } else if (name.equals("brand_name")) {
       food.brand = reader.nextString();
     } else if (name.equals("nf_serving_size_qty")) {
       double serving = reader.nextDouble();
       // we currently do nothing with this value
     } else if (name.equals("nf_serving_size_unit")) {
       String servingUnit = reader.nextString();
       // we currently do nothing with this value
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return;
 }
Пример #14
0
 private FoodItem readFoodInfo(JsonReader reader) throws IOException {
   FoodItem food = new FoodItem();
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("item_name") && reader.peek() != JsonToken.NULL) {
       food.setName(reader.nextString());
     } else if (name.equals("brand_name") && reader.peek() != JsonToken.NULL) {
       food.setBrand(reader.nextString());
     } else if (name.equals("nf_serving_size_qty") && reader.peek() != JsonToken.NULL) {
       food.setServingSize(reader.nextDouble());
     } else if (name.equals("nf_serving_size_unit") && reader.peek() != JsonToken.NULL) {
       food.setServingSizeUnit(reader.nextString());
     } else if (name.equals("nf_calories")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Calories", 0.0);
         reader.skipValue();
       } else {
         food.setField("Calories", reader.nextDouble());
       }
     } else if (name.equals("nf_total_fat")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Total Fat", 0.0);
         reader.skipValue();
       } else {
         food.setField("Total Fat", reader.nextDouble());
       }
     } else if (name.equals("nf_sodium")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Sodium", 0.0);
         reader.skipValue();
       } else {
         food.setField("Sodium", reader.nextDouble());
       }
     } else if (name.equals("nf_total_carbohydrate")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Total Carbohydrate", 0.0);
         reader.skipValue();
       } else {
         food.setField("Total Carbohydrate", reader.nextDouble());
       }
     } else if (name.equals("nf_sugars")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Sugars", 0.0);
         reader.skipValue();
       } else {
         food.setField("Sugars", reader.nextDouble());
       }
     } else if (name.equals("nf_protein")) {
       if (reader.peek() == JsonToken.NULL) {
         food.setField("Protein", 0.0);
         reader.skipValue();
       } else {
         food.setField("Protein", reader.nextDouble());
       }
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return food;
 }