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(); } }
@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; }
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(); } }
private SaroEntry processSaroEntry(JsonReader reader) throws IOException { SaroEntry entry = new SaroEntry(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("year")) { entry.setYear(reader.nextInt()); } else if (name.equals("department_code")) { entry.setDepartmentCode(reader.nextString()); } else if (name.equals("agency_code")) { entry.setAgencyCode(reader.nextString()); } else if (name.equals("operating_unit")) { entry.setOperatingUnit(reader.nextString()); } else if (name.equals("spf_code")) { entry.setSpfCode(reader.nextString()); } else if (name.equals("sub_spf_code")) { entry.setSubSpfCode(reader.nextString()); } else if (name.equals("description")) { entry.setDescription(reader.nextString()); } else if (name.equals("fund_code")) { entry.setFundCode(reader.nextString()); } else if (name.equals("region")) { entry.setRegion(reader.nextString()); } else if (name.equals("appro_src")) { entry.setAppropriationSource(reader.nextString()); } else if (name.equals("purpose")) { entry.setPurpose(reader.nextString()); } else if (name.equals("program_code")) { entry.setProgramCode(reader.nextString()); } else if (name.equals("program_description")) { entry.setProgramDescription(reader.nextString()); } else if (name.equals("object_code")) { entry.setObjectCode(reader.nextString()); } else if (name.equals("object_description")) { entry.setObjectDescription(reader.nextString()); } else if (name.equals("amount")) { entry.setAmount(reader.nextLong()); } else if (name.equals("issue_date")) { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); try { cal.setTime(sdf.parse(reader.nextString())); entry.setIssueDate(cal); } catch (ParseException e) { e.printStackTrace(); Log.e( "SAROHTTPHANDLER", "cannot parse time... format may have changed (MM/dd/yyyy HH:mm:ss format is accepted)"); entry.setIssueDate(null); } } else if (name.equals("barcode_no")) { entry.setBarcodeNumber(reader.nextString()); } else if (name.equals("saro_no")) { entry.setSaroNumber(reader.nextString()); } else if (name.equals("id")) { entry.setId(reader.nextString()); } else { Log.e( "SAROHTTPHANDLER", "schema for this request may have changed... " + "it's the government's fault, if anyone asks."); } } reader.endObject(); return entry; }
private Post readPostObject(JsonReader reader) throws Exception { Post post = new Post(); post.board = loadable.board; reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); switch (key) { case "no": // Post number post.no = reader.nextInt(); /*} else if (key.equals("time")) { // Time long time = reader.nextLong(); post.date = new Date(time * 1000);*/ break; case "now": post.date = reader.nextString(); break; case "name": post.name = reader.nextString(); break; case "com": post.rawComment = reader.nextString(); break; case "tim": post.tim = reader.nextLong(); break; case "time": post.time = reader.nextLong(); break; case "ext": post.ext = reader.nextString().replace(".", ""); break; case "resto": post.resto = reader.nextInt(); break; case "w": post.imageWidth = reader.nextInt(); break; case "h": post.imageHeight = reader.nextInt(); break; case "fsize": post.fileSize = reader.nextInt(); break; case "sub": post.subject = reader.nextString(); break; case "replies": post.replies = reader.nextInt(); break; case "filename": post.filename = reader.nextString(); break; case "sticky": post.sticky = reader.nextInt() == 1; break; case "closed": post.closed = reader.nextInt() == 1; break; case "archived": post.archived = reader.nextInt() == 1; break; case "trip": post.tripcode = reader.nextString(); break; case "country": post.country = reader.nextString(); break; case "country_name": post.countryName = reader.nextString(); break; case "id": post.id = reader.nextString(); break; case "capcode": post.capcode = reader.nextString(); break; case "images": post.images = reader.nextInt(); break; case "spoiler": post.spoiler = reader.nextInt() == 1; break; default: // Unknown/ignored key // log("Unknown/ignored key: " + key + "."); reader.skipValue(); break; } } reader.endObject(); Post cachedResult = null; for (Post possibleCached : cached) { if (possibleCached.no == post.no) { cachedResult = possibleCached; break; } } if (cachedResult != null) { return cachedResult; } else { if (!post.finish()) { throw new IOException("Incorrect data about post received."); } return post; } }