List of usage examples for android.util JsonReader endArray
public void endArray() throws IOException
From source file:com.fuzz.android.limelight.util.JSONTool.java
/** * @param reader//from www .jav a2 s . c o m * @return list of BaseChapter objects and ChapterTransition objects from JSON * @throws IOException */ public static ArrayList<Chapter> readChapterArray(JsonReader reader) throws IOException { ArrayList<Chapter> chapters = new ArrayList<Chapter>(); reader.beginArray(); while (reader.hasNext()) { reader.beginObject(); String name = reader.nextName(); if (name.equals("type")) { String type = reader.nextString(); if (type.equals("transition")) { chapters.add(readTransition(reader)); } else if (type.equals("chapter")) { chapters.add(readChapter(reader)); } } } reader.endArray(); return chapters; }
From source file:android.support.test.espresso.web.model.ModelCodec.java
private static List<Object> decodeArray(JsonReader reader) throws IOException { List<Object> array = Lists.newArrayList(); reader.beginArray();//w w w . j a v a 2s . com while (reader.hasNext()) { switch (reader.peek()) { case BEGIN_OBJECT: array.add(decodeObject(reader)); break; case NULL: reader.nextNull(); array.add(null); break; case STRING: array.add(reader.nextString()); break; case BOOLEAN: array.add(reader.nextBoolean()); break; case BEGIN_ARRAY: array.add(decodeArray(reader)); break; case NUMBER: array.add(decodeNumber(reader.nextString())); break; default: throw new IllegalStateException(String.format("%s: bogus token", reader.peek())); } } reader.endArray(); return array; }
From source file:com.workday.autoparse.json.parser.JsonParserUtils.java
/** * Parse the next value as an array, but do not attempt to convert it into a {@link Collection}, * or to convert any children into known types. The returned object will be a {@link JSONArray} * and all children will be JSONObjects, JSONArrays, and primitives. * * @param reader The JsonReader to use. Calls to {@link JsonReader#beginArray()} and {@link * JsonReader#endArray()} 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.//from w w w .j a v a2s .c o m */ public static JSONArray parseAsJsonArray(JsonReader reader, String key) throws IOException { if (handleNull(reader)) { return null; } assertType(reader, key, JsonToken.BEGIN_ARRAY); JSONArray jsonArray = new JSONArray(); reader.beginArray(); while (reader.hasNext()) { jsonArray.put(parseNextValue(reader, false)); } reader.endArray(); return jsonArray; }
From source file:org.opensilk.music.ui2.loader.PluginLoader.java
public List<ComponentName> readDisabledPlugins() { List<ComponentName> list = new ArrayList<>(); String json = settings.getString(PREF_DISABLED_PLUGINS, null); Timber.v("Read disabled plugins=" + json); if (json != null) { JsonReader jr = new JsonReader(new StringReader(json)); try {/*ww w .j a va2 s.com*/ jr.beginArray(); while (jr.hasNext()) { list.add(ComponentName.unflattenFromString(jr.nextString())); } jr.endArray(); } catch (IOException e) { settings.remove(PREF_DISABLED_PLUGINS); list.clear(); } finally { IOUtils.closeQuietly(jr); } } return list; }
From source file:com.thingsee.tracker.REST.KiiBucketRequestAsyncTask.java
private JSONArray readSensorDataFromString(String input, int offset) { StringReader reader = new StringReader(input); try {/*w ww. ja va 2s . co m*/ reader.skip(offset); } catch (IOException e1) { e1.printStackTrace(); } JsonReader jsonReader = new JsonReader(reader); JSONArray jsonArray = new JSONArray(); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { JSONObject jsonObject = readSingleData(jsonReader); jsonArray.put(jsonObject); } jsonReader.endArray(); } catch (IOException e) { // Ignore for brevity } catch (JSONException e) { // Ignore for brevity } try { jsonReader.close(); } catch (IOException e) { // Ignore for brevity } reader.close(); return jsonArray; }
From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java
private ArrayList<ShotLog> readList(JsonReader reader) throws ParseException { ArrayList<ShotLog> shotLogs = new ArrayList<>(); try {//ww w . ja v a 2s. c om reader.beginArray(); while (reader.hasNext()) { shotLogs.add(readShotLog(reader)); } reader.endArray(); } catch (IOException e) { e.printStackTrace(); } return shotLogs; }
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();// w ww . j av a 2s. c o m 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.example.propertylist.handler.JsonPropertyHandler.java
/** * Parses an array in the JSON data stream. * * @param reader// w w w .j av a 2 s . co m * the {@link android.util.JsonReader} used to read in the data * @return * the propertySalesPopulated * @throws java.io.IOException */ public List<Property> parseDataArray(JsonReader reader) throws IOException { List<Property> propertySalesPopulated = new ArrayList<Property>(); Property allProperty; reader.beginArray(); reader.peek(); while (reader.hasNext()) { allProperty = parseSalesData(reader); if ((allProperty.getFullAddress() != null && allProperty.mFullAddress.length() > 0) && (allProperty.getThumbnailUrl() != null && allProperty.mThumbnailUrl.length() > 0)) { propertySalesPopulated.add(allProperty); } reader.peek(); } reader.endArray(); return propertySalesPopulated; }
From source file:br.com.thinkti.android.filechooserfrag.fragFileChooserQuizlet.java
private void getSets(JsonReader reader, List list) throws IOException { reader.beginArray();// w w w. java 2s . co m while (reader.hasNext()) { list.add(parseSetJson(reader)); } reader.endArray(); }
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 w w w. j a va 2 s .c o m*/ * @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); } }