コード例 #1
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();
  }
コード例 #2
0
  @Override
  public void onHttpRequestComplete(Intent intent) {
    if (mProgressDialog != null && mProgressDialog.isShowing()) {
      mProgressDialog.dismiss();
    }

    if (intent.getIntExtra(Constants.IntentExtras.REQUEST_ID, -1)
        == Constants.ApiRequestId.GET_EMOJIS_DATA) {

      try {
        String trendingShows = intent.getStringExtra(Constants.IntentExtras.MESSAGE);
        JsonReader jsonReader = new JsonReader(new StringReader(trendingShows));
        jsonReader.beginObject();
        while (jsonReader.hasNext()) {
          String emojisName = jsonReader.nextName();
          String emojisImageUrl = jsonReader.nextString();
          Log.d(getTag(), emojisName + ":" + emojisImageUrl);
          EmojiData emojiData = new EmojiData();
          emojiData.setEmojisName(emojisName);
          emojiData.setEmojisImageUrl(emojisImageUrl);
          emojiDataList.add(emojiData);
        }
        jsonReader.endObject();
        this.emojisListAdapter.notifyDataSetChanged();
      } catch (IOException e) {
        e.printStackTrace();
        Log.e(getTag(), e.getMessage());
      }
    }
  }
コード例 #3
0
  private void parseWeatherFormWeather(JsonReader reader) throws IOException {
    Log.d(TAG, "Entering parseWeatherFormWeather");

    reader.beginArray();
    reader.beginObject();
    try {
      while (reader.hasNext()) {
        String name = reader.nextName();
        switch (name) {
          case JsonWeatherTokens.DESCRIPTION:
            weatherData.setWeather(reader.nextString());
            break;
          case JsonWeatherTokens.ICON:
            weatherData.setIcon(reader.nextString());
            break;
          default:
            reader.skipValue();
            break;
        }
      }
    } finally {
      reader.endObject();
      reader.endArray();
    }
  }
コード例 #4
0
  private void readErthquake(JsonReader reader) throws IOException {
    String s;
    reader.beginObject();
    while (reader.hasNext()) {
      s = reader.nextName();
      if (s.equals("properties")) {
        readProperties(reader);
      } else if (s.equals("geometry")) {
        readGeometry(reader);
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();

    final Quake quake = new Quake(date, details, location, magnitude, link);

    // Process a newly found earthquake
    handler.post(
        new Runnable() {
          public void run() {
            addNewQuake(quake);
          }
        });
  }
コード例 #5
0
  private void parseWeatherServiceResults(JsonReader reader) throws IOException {

    Log.d(TAG, "Entering parse Weather Service Results");
    reader.beginObject();
    try {
      while (reader.hasNext()) {
        String name = reader.nextName();
        switch (name) {
          case JsonWeatherTokens.SYS:
            if (reader.peek() == JsonToken.BEGIN_OBJECT) {
              parseWeatherFormSys(reader);
              break;
            }
          case JsonWeatherTokens.WEATHER:
            parseWeatherFormWeather(reader);
            break;
          case JsonWeatherTokens.MAIN:
            parseWeatherFormMain(reader);
            break;
          case JsonWeatherTokens.WIND:
            parseWeatherFormWind(reader);
            break;
          case JsonWeatherTokens.NAME:
            weatherData.setCity(reader.nextString());
            break;
          default:
            reader.skipValue();
            break;
        }
      }
    } finally {
      reader.endObject();
    }
  }
コード例 #6
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;
  }
コード例 #7
0
  private List<Post> loadCatalog(JsonReader reader) throws Exception {
    ArrayList<Post> list = new ArrayList<>();

    reader.beginArray(); // Array of pages

    while (reader.hasNext()) {
      reader.beginObject(); // Page object

      while (reader.hasNext()) {
        if (reader.nextName().equals("threads")) {
          reader.beginArray(); // Threads array

          while (reader.hasNext()) {
            list.add(readPostObject(reader));
          }

          reader.endArray();
        } else {
          reader.skipValue();
        }
      }

      reader.endObject();
    }

    reader.endArray();

    return list;
  }
コード例 #8
0
 @SuppressWarnings("cast")
 public static some.test.Simple createUsingJsonStream(Realm realm, JsonReader reader)
     throws IOException {
   some.test.Simple obj = realm.createObject(some.test.Simple.class);
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("name")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         ((SimpleRealmProxyInterface) obj).realmSet$name(null);
       } else {
         ((SimpleRealmProxyInterface) obj).realmSet$name((String) reader.nextString());
       }
     } else if (name.equals("age")) {
       if (reader.peek() == JsonToken.NULL) {
         reader.skipValue();
         throw new IllegalArgumentException("Trying to set non-nullable field 'age' to null.");
       } else {
         ((SimpleRealmProxyInterface) obj).realmSet$age((int) reader.nextInt());
       }
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
   return obj;
 }
コード例 #9
0
 private void parseWeatherFormSys(JsonReader reader) throws IOException {
   Log.d(TAG, "Entering parseWeatherFormSys");
   reader.beginObject();
   try {
     while (reader.hasNext()) {
       String name = reader.nextName();
       switch (name) {
         case JsonWeatherTokens.COUNTRY:
           weatherData.setCountry(reader.nextString());
           break;
         case JsonWeatherTokens.SUNRISE:
           weatherData.setSunrise(reader.nextLong());
           break;
         case JsonWeatherTokens.SUNSET:
           weatherData.setSunset(reader.nextLong());
           break;
         default:
           reader.skipValue();
           break;
       }
     }
   } finally {
     reader.endObject();
   }
 }
コード例 #10
0
ファイル: RepoParser.java プロジェクト: vezikon/Github_Sample
  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;
  }
コード例 #11
0
ファイル: SnippetsManager.java プロジェクト: xar369/chromium
    private SnippetArticle readArticleDetails(JsonReader reader) throws IOException {
      String headline = "";
      String publisher = "";
      String snippets = "";
      String url = "";
      String thumbnail = "";

      reader.beginObject();
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("headline")) {
          headline = reader.nextString();
        } else if (name.equals("publisher")) {
          publisher = reader.nextString();
        } else if (name.equals("snippet")) {
          snippets = reader.nextString();
        } else if (name.equals("url")) {
          url = reader.nextString();
        } else if (name.equals("thumbnail")) {
          thumbnail = reader.nextString();
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();
      return new SnippetsManager.SnippetArticle(
          headline, publisher, snippets, url, thumbnail, mNumArticles++);
    }
コード例 #12
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;
    }
コード例 #13
0
  @Override
  public void onMessage(int instanceId, String message) {
    StringReader contents = new StringReader(message);
    JsonReader reader = new JsonReader(contents);

    int requestId = -1;
    String cmd = null;
    String url = null;
    try {
      reader.beginObject();
      while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(TAG_CMD)) {
          cmd = reader.nextString();
        } else if (name.equals(TAG_REQUEST_ID)) {
          requestId = reader.nextInt();
        } else if (name.equals("url")) {
          url = reader.nextString();
        } else {
          reader.skipValue();
        }
      }
      reader.endObject();
      reader.close();

      if (cmd != null && cmd.equals(CMD_REQUEST_SHOW) && requestId >= 0) {
        handleRequestShow(instanceId, url, requestId);
      }
    } catch (IOException e) {
      Log.d(TAG, "Error: " + e);
    }
  }
コード例 #14
0
ファイル: JsonParser.java プロジェクト: malditotm/ANF_AS
  public ArrayList<Promotion> parsePromotionList(JsonReader jsonReader) {
    ArrayList<Promotion> promoList = new ArrayList<Promotion>();

    try {
      jsonReader.beginObject();
      while (jsonReader.hasNext()) {
        String name = jsonReader.nextName();
        if (name.equals(JSON_KEY_PROMOTIONS) && jsonReader.peek() != JsonToken.NULL) {

          jsonReader.beginArray();
          while (jsonReader.hasNext()) {
            Promotion promo = parsePromotion(jsonReader);
            if (promo != null) {
              promoList.add(promo);
            }
          }
          jsonReader.endArray();

        } else {
          jsonReader.skipValue();
        }
      }
      jsonReader.endObject();

    } catch (IOException e) {
    }

    return promoList;
  }
コード例 #15
0
ファイル: JsonParser.java プロジェクト: malditotm/ANF_AS
  public Promotion parsePromotion(JsonReader jsonReader) {
    Promotion promo = new Promotion();

    try {
      jsonReader.beginObject();
      while (jsonReader.hasNext()) {
        String name = jsonReader.nextName();
        if (name.equals(JSON_KEY_BUTTON)) {
          promo.setButton(parseButton(jsonReader));
        } else if (name.equals(JSON_KEY_DESCRIPTION)) {
          promo.setDescription(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_FOOTER)) {
          promo.setFooter(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_TITLE)) {
          promo.setTitle(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_IMAGE)) {
          promo.setImage(jsonReader.nextString());
        } else {
          jsonReader.skipValue();
        }
      }
      jsonReader.endObject();

    } catch (IOException e) {
    }

    return promo;
  }
コード例 #16
0
  /**
   * Parses the raw JSON resource specified by {@code metadataResId}. The JSON is expected to be in
   * this format: { "apiVersion": <version number (string)>, "densities": [ { "density": <density
   * (int)>, "width": <unscaled sprite width (int)>, "height": <unscaled sprite height (int)>,
   * "rectangles": [ [<list of ints for frame 0>], [<list of ints for frame 1>], ...... ] }, {
   * "density": <density (int)>, "width": <unscaled sprite width (int)>, "height": <unscaled sprite
   * height (int)>, "rectangles": [ [<list of ints for frame 0>], [<list of ints for frame 1>],
   * ...... ] }, ...... ] }
   *
   * @param metadataResId The id of the raw resource containing JSON to parse.
   * @param bitmapDensity The density of the unscaled {@link Bitmap} that was loaded.
   * @param resources A {@link Resources} instance to load assets from.
   * @throws IOException
   */
  @VisibleForTesting
  void parseMetadata(int metadataResId, int bitmapDensity, Resources resources) throws IOException {
    InputStream inputStream = resources.openRawResource(metadataResId);
    JsonReader reader = new JsonReader(new InputStreamReader(inputStream));
    try {
      reader.beginObject(); // Start reading top-level object.

      // Check apiVersion.
      String name = reader.nextName();
      assert name.equals("apiVersion");
      String version = reader.nextString();
      assert version.equals("1.0");

      // Parse array of densities.
      name = reader.nextName();
      assert name.equals("densities");
      reader.beginArray(); // Start reading array of densities.
      while (reader.hasNext()) {
        reader.beginObject(); // Start reading object for this density.
        boolean foundDensity = parseMetadataForDensity(reader, bitmapDensity);
        reader.endObject(); // Stop reading object for this density.

        if (foundDensity) break;
      }
    } finally {
      reader.close();
      inputStream.close();
    }
  }
コード例 #17
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  public ArrayList<Song> parseSongList(JsonReader jsonReader) {
    ArrayList<Song> songList = new ArrayList<Song>();

    try {
      jsonReader.beginObject();
      while (jsonReader.hasNext()) {
        String name = jsonReader.nextName();
        if (name.equals(JSON_KEY_RESULTS) && jsonReader.peek() != JsonToken.NULL) {

          jsonReader.beginArray();
          while (jsonReader.hasNext()) {
            Song song = parseSong(jsonReader);
            if (song != null) {
              songList.add(song);
            }
          }
          jsonReader.endArray();

        } else {
          jsonReader.skipValue();
        }
      }
      jsonReader.endObject();

    } catch (IOException e) {
    }

    return songList;
  }
コード例 #18
0
ファイル: Usuario.java プロジェクト: tomasnfranco/TDP2Grupo9
 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();
 }
コード例 #19
0
ファイル: JsonParser.java プロジェクト: malditotm/ANF_AS
  public Button parseButton(JsonReader jsonReader) {
    Button button = new Button();

    try {
      jsonReader.beginObject();
      while (jsonReader.hasNext()) {
        String name = jsonReader.nextName();
        if (name.equals(JSON_KEY_BUT_TARGET)) {
          button.setTarget(jsonReader.nextString());
        } else if (name.equals(JSON_KEY_BUT_TITLE)) {
          button.setTitle(jsonReader.nextString());
        } else {
          jsonReader.skipValue();
        }
      }
      jsonReader.endObject();

    } catch (IOException e) {
    } catch (Exception e) {

      try {
        jsonReader.beginArray();
        jsonReader.beginObject();
        while (jsonReader.hasNext()) {
          String name = jsonReader.nextName();
          if (name.equals(JSON_KEY_BUT_TARGET)) {
            button.setTarget(jsonReader.nextString());
          } else if (name.equals(JSON_KEY_BUT_TITLE)) {
            button.setTitle(jsonReader.nextString());
          } else {
            jsonReader.skipValue();
          }
        }
        jsonReader.endObject();
        jsonReader.endArray();

      } catch (IOException e2) {
      }
    }

    return button;
  }
コード例 #20
0
  /** Parse single metric body */
  void parseBody() throws IOException {

    // reset values
    String metricId = null;
    int lastRowId = 0;
    String instanceId = null;
    String serverName = null;
    String name = null;
    JSONObject parameters = null;

    _reader.beginObject();
    while (_reader.hasNext()) {
      String property = _reader.nextName();
      switch (property) {
        case "uid":
          metricId = nextStringOrNull();
          break;
        case "last_rowid":
          lastRowId = _reader.nextInt();
          break;
        case "name":
          name = nextStringOrNull();
          break;
        case "server":
          instanceId = nextStringOrNull();
          break;
        case "tag_name":
          serverName = nextStringOrNull();
          break;
        case "parameters":
          parameters = nextObjectOrNull();
          break;
        default:
          _reader.skipValue();
          break;
      }
    }
    _reader.endObject();

    serverName = serverName == null ? instanceId : serverName;
    Metric metric =
        HTMITApplication.getDatabase()
            .getDataFactory()
            .createMetric(metricId, name, instanceId, serverName, lastRowId, parameters);

    String unit = metric.getUnit();
    if (unit == null) {
      // Guess metric unit based on name if not given by server
      unit = HTMITApplication.getMetricUnit(name);
      metric.setUnit(unit);
    }

    _results.add(metric);
  }
コード例 #21
0
  public void deSerializeRepresentation(JsonReader reader) throws IOException {
    ArrayList<String[]> al = new ArrayList<String[]>();
    reader.beginObject();
    while (reader.hasNext()) {
      String[] kv = {reader.nextName(), reader.nextString()};
      al.add(kv);
    }
    reader.endObject();
    String[][] oldFormat = al.toArray(new String[al.size()][]);

    deSerializeRepresentation(oldFormat);
  }
コード例 #22
0
 private void readEarthquakes(JsonReader reader) throws IOException {
   reader.beginObject();
   while (reader.hasNext()) {
     String s = reader.nextName();
     if (s.equals("features")) {
       readFeaturesArray(reader);
     } else {
       reader.skipValue();
     }
   }
   reader.endObject();
 }
コード例 #23
0
  private void readMessage(JsonReader reader) throws IOException {

    String name = null;
    String zone = null;
    String apn = null;
    String address = null;

    reader.beginObject();
    while (reader.hasNext()) {

      tag = reader.nextName();

      if (tag.equals("name")) {
        name = reader.nextString();
      } else if (tag.equals("zone")) {
        zone = reader.nextString();
      } else if (tag.equals("apn")) {
        apn = reader.nextString();
      } else if (tag.equals("address")) {
        address = reader.nextString();
      } else if (tag.equals("feature") && reader.peek() != JsonToken.NULL) {
        polygonPath = readLatLngArray(reader);
      } else {
        reader.skipValue();
      }
    } // while

    reader.endObject();

    // create new marker and polygon
    if (address != null && !address.isEmpty()) {
      address = address + ", COSTA MESA, CA";
    }

    polyopts = new PolygonOptions().addAll(polygonPath);
    polyopts.fillColor(randomColor());
    polyopts.strokeColor(Color.YELLOW);
    polyopts.strokeWidth(1);

    polygon = map.addPolygon(polyopts);

    marker =
        map.addMarker(
            new MarkerOptions()
                .position(polygon.getPoints().get(0))
                .title(address)
                .snippet("APN :[" + apn + "]  Zone : (" + zone + ") ")
                .anchor(0.5f, 0.5f)
                .infoWindowAnchor(0.5f, 0.5f)
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.house2)));
    marker.setVisible(false);
  }
コード例 #24
0
ファイル: SnippetsManager.java プロジェクト: xar369/chromium
 private void readSnippetGroup(List<SnippetListItem> listSnippetItems, JsonReader reader)
     throws IOException {
   reader.beginObject();
   while (reader.hasNext()) {
     String name = reader.nextName();
     if (name.equals("recommendation_basis")) {
       listSnippetItems.add(new SnippetHeader(reader.nextString()));
     } else if (name.equals("articles")) {
       readArticlesArray(listSnippetItems, reader);
     }
   }
   reader.endObject();
 }
コード例 #25
0
ファイル: Response.java プロジェクト: sni01/Android_Projects
 public Response(JsonReader jsonReader) {
   results = new HashMap<String, String>();
   try {
     jsonReader.beginObject();
     while (jsonReader.peek() != JsonToken.END_OBJECT) {
       String label = jsonReader.nextName();
       results.put(label, jsonReader.nextString());
     }
     jsonReader.endObject();
   } catch (IOException e) {
     Log.i("RESPONSE :", e.getMessage());
   }
 }
コード例 #26
0
  private List<Post> loadBoard(JsonReader reader) throws Exception {
    ArrayList<Post> list = new ArrayList<>();

    reader.beginObject(); // Threads array

    if (reader.nextName().equals("threads")) {
      reader.beginArray();

      while (reader.hasNext()) {
        reader.beginObject(); // Thread object

        if (reader.nextName().equals("posts")) {
          reader.beginArray();

          list.add(readPostObject(reader));

          // Only consume one post
          while (reader.hasNext()) reader.skipValue();

          reader.endArray();
        } else {
          reader.skipValue();
        }

        reader.endObject();
      }

      reader.endArray();
    } else {
      reader.skipValue();
    }

    reader.endObject();

    return list;
  }
コード例 #27
0
ファイル: JsonParser.java プロジェクト: clsera/Bingo
  public List<Image> readImages(JsonReader reader) throws IOException {
    List<Image> images = new ArrayList<>();

    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();
      if ("images".equals(name)) {
        images.addAll(readImagesArray(reader));
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();
    return images;
  }
コード例 #28
0
  /** Peeks at the next token and returns a {@link org.json.JSONObject} or {@code null} */
  JSONObject nextObjectOrNull() throws IOException {
    if (_reader.peek() == JsonToken.NULL) {
      _reader.nextNull();
      return null;
    }
    JSONObject json = new JSONObject();
    String name;
    Object value;
    _reader.beginObject();
    while (_reader.hasNext()) {
      name = _reader.nextName();
      switch (_reader.peek()) {
        case STRING:
          value = nextStringOrNull();
          break;
        case BEGIN_ARRAY:
          value = nextArrayOrNull();
          break;
        case BEGIN_OBJECT:
          value = nextObjectOrNull();
          break;
        case BOOLEAN:
          value = nextBooleanOrNull();
          break;
        case NUMBER:
          value = nextNumberOrNull();
          break;
        case NULL:
          _reader.nextNull();
          value = null;
          break;
        default:
          _reader.skipValue();
          value = null;
      }
      try {
        json.put(name, value);
      } catch (JSONException e) {
        Log.e(
            getClass().getSimpleName(),
            "Failed to parse JSON object: " + name + ", value = " + value);
      }
    }
    _reader.endObject();

    return json;
  }
コード例 #29
0
ファイル: RepoParser.java プロジェクト: vezikon/Github_Sample
  public void ReadOwnerMessage(JsonReader reader) throws IOException {

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

      if (name.equals("login")) {
        repo.setOwner_name(reader.nextString());
      } else if (name.equals("html_url")) {
        repo.setOwner_url(reader.nextString());
      } else {
        reader.skipValue();
      }
    }

    reader.endObject();
  }
コード例 #30
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;
 }