List of usage examples for android.util JsonReader endArray
public void endArray() throws IOException
From source file:watch.oms.omswatch.parser.OMSConfigDBParser.java
private List<ContentValues> readAllRowDataForTable(JsonReader reader, String pTableName) throws IOException { List<ContentValues> messages = new ArrayList<ContentValues>(); ContentValues contentValues = null;//from w w w . j a v a2 s . c om int skippedRowsCount = 0; reader.beginArray(); while (reader.hasNext()) { contentValues = readSingleRowData(reader); if (validateRowData(contentValues)) { messages.add(contentValues); } else { skippedRowsCount++; } } if (skippedRowsCount > 0) { Log.d(TAG, "Skipped #" + skippedRowsCount + " records for table - " + pTableName); } reader.endArray(); return messages; }
From source file:com.dalaran.async.task.http.AbstractHTTPService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected List<ContentValues> parseJson(JsonReader reader) throws IOException { List<ContentValues> contentValueses = new ArrayList<ContentValues>(); ContentValues values = new ContentValues(); Long threadId = 0L;//from w w w .ja va2 s . c o m boolean notEnd = true; String name = ""; if (reader.hasNext()) { //todo android.util.MalformedJsonException: Use JsonReader.setLenient(true) do { switch (reader.peek()) { case BEGIN_OBJECT: values = new ContentValues(); if (threadId != 0) { values.put("threadId", threadId); } reader.beginObject(); break; case BEGIN_ARRAY: if (values != null && values.getAsLong("threadId") != null) { threadId = values.getAsLong("threadId"); } reader.beginArray(); break; case BOOLEAN: values.put(name, reader.nextBoolean()); break; case END_ARRAY: reader.endArray(); break; case END_DOCUMENT: notEnd = false; break; case END_OBJECT: contentValueses.add(values); reader.endObject(); break; case NAME: name = reader.nextName(); break; case NULL: reader.nextNull(); break; case NUMBER: values.put(name, reader.nextDouble()); break; case STRING: values.put(name, reader.nextString()); break; default: reader.skipValue(); } } while (notEnd); } return contentValueses; }
From source file:com.tcity.android.ui.info.BuildArtifactsTask.java
private void handleFiles(@NotNull JsonReader reader) throws IOException { reader.beginArray();//from w ww . j ava 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; }
From source file:ngo.music.soundcloudplayer.controller.SongController.java
/** * get stack of songs played/* www. 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.workday.autoparse.json.parser.JsonParserUtils.java
/** * Parse an array that has only non-array children into a {@link Collection}. * * @param reader The reader to use, whose next token should either be {@link JsonToken#NULL} or * {@link JsonToken#BEGIN_ARRAY}./*from www. jav a 2 s .c o m*/ * @param collection The Collection to populate. The parametrization should match {@code * typeClass}. * @param itemParser The parser to use for items of the array. May be null. * @param typeClass The type of items to expect in the array. May not be null, but may be * Object.class. * @param key The key corresponding to the current value. This is used to make more useful error * messages. */ private static <T> void parseFlatJsonArray(JsonReader reader, Collection<T> collection, JsonObjectParser<T> itemParser, Class<T> typeClass, String key) throws IOException { if (handleNull(reader)) { return; } Converter<T> converter = null; if (Converters.isConvertibleFromString(typeClass)) { converter = Converters.getConverter(typeClass); } final String discriminationName = ContextHolder.getContext().getSettings().getDiscriminationName(); reader.beginArray(); while (reader.hasNext()) { Object nextValue; final JsonToken nextToken = reader.peek(); if (itemParser != null && nextToken == JsonToken.BEGIN_OBJECT) { reader.beginObject(); nextValue = itemParser.parseJsonObject(null, reader, discriminationName, null); reader.endObject(); } else if (converter != null && (nextToken == JsonToken.NUMBER || nextToken == JsonToken.STRING)) { nextValue = converter.convert(reader.nextString()); } else { nextValue = parseNextValue(reader); } if (typeClass.isInstance(nextValue)) { // This is safe since we are calling class.isInstance() @SuppressWarnings("unchecked") T toAdd = (T) nextValue; collection.add(toAdd); } else { throw new IllegalStateException( String.format(Locale.US, "Could not convert value in array at \"%s\" to %s from %s.", key, typeClass.getCanonicalName(), getClassName(nextValue))); } } reader.endArray(); }
From source file:watch.oms.omswatch.actioncenter.helpers.WatchTransDBParser.java
private List<ContentValues> readAllRowDataForTable(JsonReader reader, String pTableName) throws IOException { List<ContentValues> messages = new ArrayList<ContentValues>(); ContentValues contentValues = null;/* www.ja va 2 s.com*/ List<String> transColsSet = new ArrayList<String>(); int skippedRowsCount = 0; if (pTableName != null) { transColsSet = servermapperhelper.getTransColumnSet(pTableName); } reader.beginArray(); while (reader.hasNext()) { contentValues = readSingleRowData(reader, transColsSet, pTableName); if (pTableName != null && validateRowData(contentValues)) { messages.add(contentValues); } else { skippedRowsCount++; } } reader.endArray(); if (skippedRowsCount > 0 && pTableName != null) { Log.d(TAG, "Skipped #" + skippedRowsCount + " records for table - " + pTableName); } return messages; }
From source file:io.realm.Realm.java
/** * Create a Realm object for each object in a JSON array. This must be done within a transaction. * JSON properties with a null value will map to the default value for the data type in Realm * and unknown properties will be ignored. * * @param clazz Type of Realm objects created. * @param inputStream JSON array as a InputStream. All objects in the array must be of the * specified class. * * @throws RealmException if mapping from JSON fails. * @throws IOException if something was wrong with the input stream. *//*from w w w .jav a2 s .c o m*/ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public <E extends RealmObject> void createAllFromJson(Class<E> clazz, InputStream inputStream) throws IOException { if (clazz == null || inputStream == null) { return; } JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); try { reader.beginArray(); while (reader.hasNext()) { configuration.getSchemaMediator().createUsingJsonStream(clazz, this, reader); } reader.endArray(); } finally { reader.close(); } }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
private List<typVok> openSet(String id) throws Exception { this.errorDescription = null; this.errorTitle = null; InputStream inputStream = null; List<typVok> list = new ArrayList<typVok>(); String Kom = ""; _main.vok.title = ""; try {/*from ww w . ja v a 2 s . co m*/ URL url = new URL(getDeckUrl(id)); /* HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if ( connection.getResponseCode() >= 400 ) { inputStream = connection.getErrorStream(); } else { inputStream = connection.getInputStream(); } */ inputStream = org.liberty.android.fantastischmemo.downloader.quizlet.lib.makeApiCall(url, _main.QuizletAccessToken); JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if ("id".equals(name)) { long intId = reader.nextLong(); /*if (page > totalPages) { }*/ } else if ("url".equals(name)) { String strUrl = reader.nextString(); } else if ("title".equals(name)) { String title = reader.nextString(); _main.vok.title = title; } else if ("created_by".equals(name)) { String created_by = reader.nextString(); Kom = _main.getString(R.string.created_by) + " " + created_by + " " + _main.getString((R.string.at)) + " <link://https://quizlet.com/ Quizlet/>"; } else if ("term_count".equals(name)) { int term_count = reader.nextInt(); } else if ("lang_terms".equals(name)) { String lang_terms = reader.nextString(); try { _LangWord = new Locale(lang_terms.replace("-", "_")); } catch (Throwable ex) { } } else if ("lang_definitions".equals(name)) { String lang_definitions = reader.nextString(); try { _LangMeaning = (new Locale(lang_definitions.replace("-", "_"))); } catch (Throwable ex) { } } else if ("terms".equals(name)) { reader.beginArray(); while (reader.hasNext()) { typVok v = parseSetDataJson(reader); String kom = v.Kom; v.Kom = Kom; if (!lib.libString.IsNullOrEmpty(kom)) { v.Kom += " " + kom; } list.add(v); } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); } reader.endArray(); } finally { if (inputStream != null) { inputStream.close(); } } return list; }
From source file:com.smc.tw.waltz.MainActivity.java
private void unsubscribeAllGcmChannel() { String deviceListText = mPreferences.getString("waltzone_local_data", null); if (deviceListText == null) return;/* ww w . java 2 s . co m*/ try { StringReader stringReader = new StringReader(deviceListText); JsonReader reader = new JsonReader(stringReader); reader.beginArray(); while (reader.hasNext()) { String deviceSerial = null; reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equals("waltzone_serial")) { deviceSerial = reader.nextString(); } else { reader.skipValue(); } } // Log.e(TAG, "Unsubscribe: WALTZ_" + deviceSerial); unsubscribeGcmChannel("WALTZ_" + deviceSerial); reader.endObject(); } reader.endArray(); reader.close(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { //e.printStackTrace(); } }