List of usage examples for android.util JsonReader endObject
public void endObject() throws IOException
From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java
private GPS readGPS(JsonReader reader) throws IOException { String longitude = null;/* w w w. j a va2s.co m*/ String latitude = null; reader.beginObject(); // reader.beginArray(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals(GPS_LONGITUDE_NAME)) longitude = reader.nextString(); else if (name.equals(GPS_LATITUDE_NAME)) latitude = reader.nextString(); else reader.skipValue(); } // reader.endArray(); reader.endObject(); GPS gps = null; if (longitude != null && latitude != null) gps = new GPS(longitude, latitude); return gps; }
From source file:com.thingsee.tracker.REST.KiiBucketRequestAsyncTask.java
private JSONObject readSingleData(JsonReader jsonReader) throws IOException, JSONException { JSONObject jsonObject = new JSONObject(); jsonReader.beginObject();//from w w w . j a v a2 s .c om JsonToken token; do { String name = jsonReader.nextName(); if ("sId".equals(name)) { jsonObject.put("sId", jsonReader.nextString()); } else if ("val".equals(name)) { jsonObject.put("val", jsonReader.nextDouble()); } else if ("ts".equals(name)) { jsonObject.put("ts", jsonReader.nextLong()); } else if ("_owner".equals(name)) { jsonObject.put("_owner", jsonReader.nextString()); } token = jsonReader.peek(); } while (token != null && !token.equals(JsonToken.END_OBJECT)); jsonReader.endObject(); return jsonObject; }
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;/*from www .j a va 2 s . c om*/ } 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:at.ac.tuwien.caa.docscan.logic.DataLog.java
private ShotLog readShotLog(JsonReader reader) throws IOException, ParseException { GPS gps = null;/*from w w w . ja v a 2s . co m*/ String dateString, fileName = null; Date date = null; boolean seriesMode = false; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals(FILE_NAME)) { fileName = reader.nextString(); } else if (name.equals(DATE_NAME)) { dateString = reader.nextString(); if (dateString != null) date = string2Date(dateString); } else if (name.equals(GPS_NAME)) { gps = readGPS(reader); } else if (name.equals(SERIES_MODE_NAME)) { seriesMode = reader.nextBoolean(); } } reader.endObject(); ShotLog shotLog = new ShotLog(fileName, gps, date, seriesMode); return shotLog; }
From source file:com.fuzz.android.limelight.util.JSONTool.java
/** * @param reader/*from w w w.ja v a 2 s .c o m*/ * @return the generated Act object from the JSON * @throws IOException */ public static Act readAct(JsonReader reader) throws IOException { int id = -1; String message = null; int messageResId = -1; int graphResId = -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; String activityName = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("id")) id = 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")) graphResId = 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(); else if (name.equals("activity_name")) activityName = reader.nextString(); else reader.skipValue(); } reader.endObject(); Act act = new Act(); act.setId(id); act.setMessage(message); act.setMessageResID(messageResId); act.setGraphicResID(graphResId); act.setIsActionBarItem(isActionBarItem); act.setDisplacement(xOffset, yOffset); act.setTextColor(textColor); act.setTextBackgroundColor(textBackgroundColor); act.setTextSize(textSize); act.setTransparentBackground(textBackgroundTransparent); act.setAnimation(animation); act.setActivityName(activityName); act.getLayout(); return act; }
From source file:watch.oms.omswatch.parser.OMSConfigDBParser.java
private ContentValues readSingleRowData(JsonReader reader) { ContentValues contentValues = new ContentValues(); String colName = null;/* w ww. j av a 2s.c o m*/ String colValue = null; try { reader.beginObject(); while (reader.hasNext()) { colName = null; colValue = null; colName = reader.nextName(); colValue = reader.nextString(); if (colValue.equals(OMSConstants.NULL_STRING)) { colValue = OMSConstants.EMPTY_STRING; } if (!colName.equalsIgnoreCase("isdirty")) { contentValues.put(colName, colValue); } } reader.endObject(); } catch (IOException e) { Log.e(TAG, "IOException:: ColName - " + (colName == null ? OMSConstants.EMPTY_STRING : colName)); e.printStackTrace(); } return contentValues; }
From source file:com.example.propertylist.handler.JsonPropertyHandler.java
/** * Loads the next observation into the property class. * * @param reader/* ww w. ja va2 s. c o m*/ * the {@link android.util.JsonReader} containing the observation * @throws java.io.IOException */ private Property parseSalesData(JsonReader reader) throws IOException { Property property = new Property(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("full_address") && reader.peek() != JsonToken.NULL) { property.setFullAddress(reader.nextString()); } else if (name.equals("daft_url") && reader.peek() != JsonToken.NULL) { property.setDaftPropertyUrl(reader.nextString()); } else if (name.equals("description") && reader.peek() != JsonToken.NULL) { property.setDescription(reader.nextString()); } else if (name.equals("small_thumbnail_url") && reader.peek() != JsonToken.NULL) { property.setThumbnailUrl(reader.nextString()); } else if (name.equals("medium_thumbnail_url") && reader.peek() != JsonToken.NULL) { property.setMediumThumbnailUrl(reader.nextString()); } else if (name.equals("large_thumbnail_url") && reader.peek() != JsonToken.NULL) { property.setLargeThumbnailUrl(reader.nextString()); } else { reader.skipValue(); } // end if hasnext } // end while reader.endObject(); return property; }
From source file:com.workday.autoparse.json.parser.JsonParserUtils.java
/** * Parse the next value as an object. If the next value is {@link JsonToken#NULL}, returns * null./*from w ww. j a v a 2 s . c o m*/ * <p/> * This method will use the provide parser, or if none is provided, will attempt find an * appropriate parser based on the discrimination value found in the next object. If none is * found, then this method returns a {@link JSONObject}. * * @param reader The JsonReader to use. Calls to {@link JsonReader#beginObject()} and {@link * JsonReader#endObject()} will be taken care of by this method. * @param parser The parser to use, or null if this method should find an appropriate one on its * own. * @param key The key corresponding to the current value. This is used to make more useful error * messages. * @param expectedType The expected class of the resulting object. If the result is not an * instance of this class, an exception is thrown. * * @throws IllegalStateException if the resulting object is not an instance of {@code * expectedType}. */ public static Object parseJsonObject(JsonReader reader, JsonObjectParser<?> parser, String key, Class<?> expectedType) throws IOException, IllegalStateException { if (handleNull(reader)) { return null; } assertType(reader, key, JsonToken.BEGIN_OBJECT); final String discriminationName = ContextHolder.getContext().getSettings().getDiscriminationName(); String discriminationValue = null; Object result = null; reader.beginObject(); if (parser != null) { result = parser.parseJsonObject(null, reader, discriminationName, null); } else if (reader.hasNext()) { String firstName = reader.nextName(); final String discriminationKeyName = ContextHolder.getContext().getSettings().getDiscriminationName(); if (discriminationKeyName.equals(firstName)) { discriminationValue = reader.nextString(); parser = ContextHolder.getContext().getJsonObjectParserTable().get(discriminationValue); if (parser != null) { result = parser.parseJsonObject(null, reader, discriminationName, discriminationValue); } else { result = parseSpecificJsonObjectDelayed(reader, discriminationKeyName, discriminationValue); } } else { result = parseSpecificJsonObjectDelayed(reader, firstName, null); } } reader.endObject(); if (result == null) { result = new JSONObject(); } JsonObjectParser<?> unknownObjectParser = ContextHolder.getContext().getSettings().getUnknownObjectParser(); if (result instanceof JSONObject && unknownObjectParser != null) { result = unknownObjectParser.parseJsonObject((JSONObject) result, null, discriminationName, discriminationValue); } if (expectedType != null && !(expectedType.isInstance(result))) { throw new IllegalStateException( String.format(Locale.US, "Could not convert value at \"%s\" to %s from %s.", key, expectedType.getCanonicalName(), result.getClass().getCanonicalName())); } return result; }
From source file:ngo.music.soundcloudplayer.controller.SongController.java
/** * get stack of songs played// w ww. j a va2s . c o m * * @return */ public ArrayList<Object[]> getSongsPlayed() { File file = new File(MusicPlayerService.getInstance().getApplicationContext() .getExternalFilesDir(Context.ACCESSIBILITY_SERVICE), filename); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } ArrayList<Object[]> songs = new ArrayList<Object[]>(); try { FileInputStream fileReader = new FileInputStream(file); JsonReader reader = new JsonReader(new InputStreamReader(fileReader)); String id = null; reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { Object[] object = new Object[2]; id = reader.nextName(); object[0] = getSong(id); object[1] = Integer.valueOf(reader.nextInt()); if (object[0] != null) { songs.add(object); } } reader.endObject(); } reader.endArray(); reader.close(); } catch (Exception e) { Log.e("get songPlayed", e.toString()); return songs; } return songs; }
From source file:com.tcity.android.ui.info.BuildArtifactsTask.java
private void handleFiles(@NotNull JsonReader reader) throws IOException { reader.beginArray();/*from w w w .jav a 2s . c o m*/ List<BuildArtifact> result = new ArrayList<>(); while (reader.hasNext()) { reader.beginObject(); long size = -1; String name = null; String contentHref = null; String childrenHref = null; while (reader.hasNext()) { switch (reader.nextName()) { case "size": size = reader.nextLong(); break; case "name": name = reader.nextString(); break; case "children": childrenHref = getHref(reader); break; case "content": contentHref = getHref(reader); break; default: reader.skipValue(); } } if (name == null) { throw new IllegalStateException("Invalid artifacts json: \"name\" is absent"); } if (contentHref == null && childrenHref == null) { throw new IllegalStateException("Invalid artifacts json: \"content\" and \"children\" are absent"); } result.add(new BuildArtifact(size, name, contentHref, childrenHref)); reader.endObject(); } reader.endArray(); myResult = result; }