List of usage examples for android.util JsonReader nextName
public String nextName() throws IOException
From source file:com.fuzz.android.limelight.util.JSONTool.java
/** * @param reader/*from w w w . j a v a 2s . c o m*/ * @return the generated ChapterTransition object from JSON * @throws IOException */ public static ChapterTransition readTransition(JsonReader reader) throws IOException { long time = -1; int itemPosition = -1; int childId = -1; int anchorId = -1; String message = null; int messageResId = -1; int grapicResID = -1; boolean isActionBarItem = false; double xOffset = -1; double yOffset = -1; int textColor = -1; int textBackgroundColor = -1; float textSize = -1; boolean textBackgroundTransparent = false; String animation = null; while (reader.hasNext()) { try { String name = reader.nextName(); if (name.equals("time")) time = reader.nextLong(); else if (name.equals("item_position")) itemPosition = reader.nextInt(); else if (name.equals("child_id")) childId = reader.nextInt(); else if (name.equals("id")) anchorId = reader.nextInt(); else if (name.equals("message")) message = reader.nextString(); else if (name.equals("message_res_id")) messageResId = reader.nextInt(); else if (name.equals("graphic_res_id")) grapicResID = reader.nextInt(); else if (name.equals("is_action_bar_item")) isActionBarItem = reader.nextBoolean(); else if (name.equals("x_offset")) xOffset = reader.nextDouble(); else if (name.equals("y_offset")) yOffset = reader.nextDouble(); else if (name.equals("text_color")) textColor = reader.nextInt(); else if (name.equals("text_background_color")) textBackgroundColor = reader.nextInt(); else if (name.equals("text_size")) textSize = reader.nextLong(); else if (name.equals("text_background_transparent")) textBackgroundTransparent = reader.nextBoolean(); else if (name.equals("animation")) animation = reader.nextString(); } catch (IllegalStateException e) { reader.nextNull(); e.printStackTrace(); } } reader.endObject(); ChapterTransition transition = new ChapterTransition(); transition.setTime(time); transition.setItemPosition(itemPosition); transition.setChildID(childId); transition.setId(anchorId); transition.setMessage(message); transition.setMessageResID(messageResId); transition.setGraphicResID(grapicResID); transition.setIsActionBarItem(isActionBarItem); transition.setDisplacement(xOffset, yOffset); transition.setTextColor(textColor); transition.setTextBackgroundColor(textBackgroundColor); transition.setTextSize(textSize); transition.setTransparentBackground(textBackgroundTransparent); transition.setAnimation(animation); return transition; }
From source file:com.workday.autoparse.json.demo.UnannotatedObjectParser.java
private void parseFromReader(UnannotatedObject out, JsonReader reader) throws IOException { while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case "string": { out.string = reader.nextString(); break; }/*from w ww . jav a 2 s .com*/ default: { reader.skipValue(); } } } }
From source file:com.workday.autoparse.json.demo.ParserAnnotatedObjectParser.java
private void parseFromReader(ParserAnnotatedObject out, JsonReader reader) throws IOException { final String discriminationName = ContextHolder.getContext().getSettings().getDiscriminationName(); while (reader.hasNext()) { String name = reader.nextName(); if (discriminationName.equals(name)) { out.discriminationValue = JsonParserUtils.nextString(reader, discriminationName); continue; }//from w w w . ja v a 2 s. c o m switch (name) { case "string": { out.string = reader.nextString(); break; } default: { reader.skipValue(); } } } }
From source file:pedromendes.tempodeespera.HospitalDetailActivity.java
public void fillQueue(JsonReader reader, EmergencyQueue queue) throws IOException { reader.nextName(); int time = reader.nextInt(); reader.nextName();// w w w. j a v a2 s. c o m int length = reader.nextInt(); queue.setTime(time); queue.setLength(length); }
From source file:com.workday.autoparse.json.parser.JsonParserUtils.java
/** * Parse the next value as an object, but do not attempt to convert it or any children to a * known type. The returned object will be a {@link JSONObject} and all children will be * JSONObjects, JSONArrays, and primitives. * * @param reader The JsonReader to use. Calls to {@link JsonReader#beginObject()} and {@link * JsonReader#endObject()} will be taken care of by this method. * @param key The key corresponding to the current value. This is used to make more useful error * messages.// w w w . j av a 2 s. c o m */ public static JSONObject parseAsJsonObject(JsonReader reader, String key) throws IOException { if (handleNull(reader)) { return null; } assertType(reader, key, JsonToken.BEGIN_OBJECT); JSONObject result = new JSONObject(); reader.beginObject(); while (reader.hasNext()) { try { result.put(reader.nextName(), parseNextValue(reader, false)); } catch (JSONException e) { throw new RuntimeException("This should be impossible.", e); } } reader.endObject(); return result; }
From source file:com.tcity.android.ui.info.BuildInfoTask.java
@Nullable private String getAgentName(@NotNull JsonReader reader) throws IOException { reader.beginObject();/*from w w w. ja v a 2 s. com*/ String result = null; while (reader.hasNext()) { switch (reader.nextName()) { case "name": result = reader.nextString(); break; default: reader.skipValue(); } } reader.endObject(); return result; }
From source file:pedromendes.tempodeespera.HospitalDetailActivity.java
public List<Emergency> readResult(JsonReader reader) throws IOException { List<Emergency> result = new ArrayList<Emergency>(); String name = reader.nextName(); if (name.equals("Result")) { reader.beginArray();/*from w w w.j ava 2 s.c om*/ while (reader.hasNext()) { reader.beginObject(); Emergency hospitalEmergencyDetail = new Emergency(); readEmergency(reader, hospitalEmergencyDetail); reader.endObject(); result.add(hospitalEmergencyDetail); } reader.endArray(); } return result; }
From source file:com.tcity.android.ui.info.BuildArtifactsTask.java
@Nullable private String getHref(@NotNull JsonReader reader) throws IOException { reader.beginObject();//from w ww . j av a2s. c o m String result = null; while (reader.hasNext()) { switch (reader.nextName()) { case "href": result = reader.nextString(); break; default: reader.skipValue(); } } reader.endObject(); return result; }
From source file:com.morlunk.leeroy.LeeroyUpdateService.java
private void handleCheckUpdates(Intent intent, boolean notify, ResultReceiver receiver) { List<LeeroyApp> appList = LeeroyApp.getApps(getPackageManager()); if (appList.size() == 0) { return;/* w w w . ja va 2 s . c o m*/ } List<LeeroyAppUpdate> updates = new LinkedList<>(); List<LeeroyApp> notUpdatedApps = new LinkedList<>(); List<LeeroyException> exceptions = new LinkedList<>(); for (LeeroyApp app : appList) { try { String paramUrl = app.getJenkinsUrl() + "/api/json?tree=lastSuccessfulBuild[number,url]"; URL url = new URL(paramUrl); URLConnection conn = url.openConnection(); Reader reader = new InputStreamReader(conn.getInputStream()); JsonReader jsonReader = new JsonReader(reader); jsonReader.beginObject(); jsonReader.nextName(); jsonReader.beginObject(); int latestSuccessfulBuild = 0; String buildUrl = null; while (jsonReader.hasNext()) { String name = jsonReader.nextName(); if ("number".equals(name)) { latestSuccessfulBuild = jsonReader.nextInt(); } else if ("url".equals(name)) { buildUrl = jsonReader.nextString(); } else { throw new RuntimeException("Unknown key " + name); } } jsonReader.endObject(); jsonReader.endObject(); jsonReader.close(); if (latestSuccessfulBuild > app.getJenkinsBuild()) { LeeroyAppUpdate update = new LeeroyAppUpdate(); update.app = app; update.newBuild = latestSuccessfulBuild; update.newBuildUrl = buildUrl; updates.add(update); } else { notUpdatedApps.add(app); } } catch (MalformedURLException e) { e.printStackTrace(); CharSequence appName = app.getApplicationInfo().loadLabel(getPackageManager()); exceptions.add(new LeeroyException(app, getString(R.string.invalid_url, appName), e)); } catch (IOException e) { e.printStackTrace(); exceptions.add(new LeeroyException(app, e)); } } if (notify) { NotificationManagerCompat nm = NotificationManagerCompat.from(this); if (updates.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_update); ncb.setTicker(getString(R.string.updates_available)); ncb.setContentTitle(getString(R.string.updates_available)); ncb.setContentText(getString(R.string.num_updates, updates.size())); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); Intent appIntent = new Intent(this, AppListActivity.class); appIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); ncb.setContentIntent( PendingIntent.getActivity(this, 0, appIntent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); for (LeeroyAppUpdate update : updates) { CharSequence appName = update.app.getApplicationInfo().loadLabel(getPackageManager()); style.addLine(getString(R.string.notify_app_update, appName, update.app.getJenkinsBuild(), update.newBuild)); } style.setSummaryText(getString(R.string.app_name)); ncb.setStyle(style); ncb.setNumber(updates.size()); nm.notify(NOTIFICATION_UPDATE, ncb.build()); } if (exceptions.size() > 0) { NotificationCompat.Builder ncb = new NotificationCompat.Builder(this); ncb.setSmallIcon(R.drawable.ic_stat_error); ncb.setTicker(getString(R.string.error_checking_updates)); ncb.setContentTitle(getString(R.string.error_checking_updates)); ncb.setContentText(getString(R.string.click_to_retry)); ncb.setPriority(NotificationCompat.PRIORITY_LOW); ncb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); ncb.setContentIntent(PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)); ncb.setAutoCancel(true); ncb.setNumber(exceptions.size()); nm.notify(NOTIFICATION_ERROR, ncb.build()); } } if (receiver != null) { Bundle results = new Bundle(); results.putParcelableArrayList(EXTRA_UPDATE_LIST, new ArrayList<>(updates)); results.putParcelableArrayList(EXTRA_NO_UPDATE_LIST, new ArrayList<>(notUpdatedApps)); results.putParcelableArrayList(EXTRA_EXCEPTION_LIST, new ArrayList<>(exceptions)); receiver.send(0, results); } }
From source file:pedromendes.tempodeespera.HospitalDetailActivity.java
private void readEmergency(JsonReader reader, Emergency hospitalEmergencyDetail) throws IOException { while (reader.hasNext()) { String fieldDame = reader.nextName(); if (fieldDame.equals("Emergency")) { reader.beginObject();//from ww w .j av a2s . c om reader.nextName(); reader.nextString(); reader.nextName(); hospitalEmergencyDetail.setDescription(reader.nextString()); reader.endObject(); } else if (fieldDame.equals("Queue") && reader.peek() != JsonToken.NULL) { reader.beginObject(); reader.nextName(); reader.nextString(); reader.nextName(); hospitalEmergencyDetail.setName(reader.nextString()); reader.endObject(); } else if (fieldDame.equals("Red")) { reader.beginObject(); fillQueue(reader, hospitalEmergencyDetail.getRedQueue()); reader.endObject(); } else if (fieldDame.equals("Orange")) { reader.beginObject(); fillQueue(reader, hospitalEmergencyDetail.getOrangeQueue()); reader.endObject(); } else if (fieldDame.equals("Yellow")) { reader.beginObject(); fillQueue(reader, hospitalEmergencyDetail.getYellowQueue()); reader.endObject(); } else if (fieldDame.equals("Green")) { reader.beginObject(); fillQueue(reader, hospitalEmergencyDetail.getGreenQueue()); reader.endObject(); } else if (fieldDame.equals("Blue")) { reader.beginObject(); fillQueue(reader, hospitalEmergencyDetail.getBlueQueue()); reader.endObject(); } else if (fieldDame.equals("LastUpdate")) { hospitalEmergencyDetail.setLastUpdate(reader.nextString()); } else { reader.skipValue(); } } }