List of usage examples for android.util JsonReader beginArray
public void beginArray() throws IOException
From source file:com.workday.autoparse.json.parser.JsonParserUtils.java
/** * Parse an array that may have arrays as 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 ww w . ja v a 2s .com*/ * @param collection The Collection to populate. If nested, the parametrization must match * {@code innerCollectionClasses} with the parametrization of the last collection matching * {@code itemType}. If not nested, the parametrization should match {@code itemType}. * @param itemParser The parser to use for the items of the most deeply nested Collections. May * be null. * @param itemType The type of the most deeply nested Collections. May not be null, but may be * Object.class. * @param innerCollectionClasses A flattened list of Collection classes that are nested within * {@code collection}. May be null. * @param key The key corresponding to the current value. This is used to make more useful error * messages. */ // Suppress rawtypes and unchecked on Collection and operations. We are depending on // innerCollectionClasses to // provide us with the types of all nested collections, and typeClass to be the parameter of // the deepest // collection. Assuming these are correct, all other operations are safe. @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> void parseJsonArray(JsonReader reader, Collection collection, JsonObjectParser<T> itemParser, Class<T> itemType, List<Class<? extends Collection>> innerCollectionClasses, String key) throws IOException { if (handleNull(reader)) { return; } assertType(reader, key, JsonToken.BEGIN_ARRAY); if (innerCollectionClasses != null && !innerCollectionClasses.isEmpty()) { CollectionInitializer nextCollectionInitializer = CollectionInitializerFactory .getCollectionInitializerForClass(innerCollectionClasses.get(0)); reader.beginArray(); while (reader.hasNext()) { Collection nextCollection = nextCollectionInitializer.newInstance(); parseJsonArray(reader, nextCollection, itemParser, itemType, innerCollectionClasses.subList(1, innerCollectionClasses.size()), key); collection.add(nextCollection); } reader.endArray(); } else { parseFlatJsonArray(reader, collection, itemParser, itemType, key); } }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
private void getSets(JsonReader reader, List list) throws IOException { reader.beginArray(); while (reader.hasNext()) { list.add(parseSetJson(reader));/*from w w w.j a va 2 s .co m*/ } reader.endArray(); }
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 www . java 2s .c om*/ 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: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;// w ww.j a v a 2 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:ngo.music.soundcloudplayer.controller.SongController.java
/** * get stack of songs played//from w w w . j a v a 2s .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.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;// w w w. j ava2s.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: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;/*w w w . j a v a 2s. c o m*/ 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. *///ww w. jav a 2s . co 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:com.smc.tw.waltz.MainActivity.java
private void unsubscribeAllGcmChannel() { String deviceListText = mPreferences.getString("waltzone_local_data", null); if (deviceListText == null) return;/* w w w.j ava 2 s .c o 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(); } }