本文整理匯總了Java中android.util.JsonReader.beginArray方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonReader.beginArray方法的具體用法?Java JsonReader.beginArray怎麽用?Java JsonReader.beginArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.util.JsonReader
的用法示例。
在下文中一共展示了JsonReader.beginArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createAllFromJson
import android.util.JsonReader; //導入方法依賴的package包/類
/**
* Creates a Realm object for each object in a JSON array. This must be done within a transaction.
* JSON properties with unknown properties will be ignored. If a {@link RealmObject} field is not present in the
* JSON object the {@link RealmObject} field will be set to the default value for that type.
* <p>
* This API is only available in API level 11 or later.
*
* <p>
* This method currently does not support value list field.
*
* @param clazz type of Realm objects created.
* @param inputStream the JSON array as a InputStream. All objects in the array must be of the specified class.
* @throws RealmException if mapping from JSON fails.
* @throws IllegalArgumentException if the JSON object doesn't have a primary key property but the corresponding
* {@link RealmObjectSchema} has a {@link io.realm.annotations.PrimaryKey} defined.
* @throws IOException if something was wrong with the input stream.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public <E extends RealmModel> void createAllFromJson(Class<E> clazz, InputStream inputStream) throws IOException {
//noinspection ConstantConditions
if (clazz == null || inputStream == null) {
return;
}
checkIfValid();
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();
}
}
示例2: processResponseMain
import android.util.JsonReader; //導入方法依賴的package包/類
private boolean processResponseMain(JsonReader reader) {
try {
mRequestResults = new ArrayList<>();
reader.beginArray();
while (reader.hasNext())
{
reader.beginObject();
if (reader.nextName().equals("reco"))
{
processResponseRecoItem(reader, mRequestResults);
}else
reader.skipValue();
reader.endObject();
}
reader.endArray();
} catch (IOException e) {
mQueryResult = QueryRecommendationResult.INCORRECT_RESPONSE;
WebtrekkLogging.log("Incorrect response structure:"+e);
mRequestResults = null;
return false;
}
return true;
}
示例3: parse
import android.util.JsonReader; //導入方法依賴的package包/類
@Override public Integer parse(JsonReader reader, float scale) throws IOException {
boolean isArray = reader.peek() == JsonToken.BEGIN_ARRAY;
if (isArray) {
reader.beginArray();
}
double r = reader.nextDouble();
double g = reader.nextDouble();
double b = reader.nextDouble();
double a = reader.nextDouble();
if (isArray) {
reader.endArray();
}
if (r <= 1 && g <= 1 && b <= 1 && a <= 1) {
r *= 255;
g *= 255;
b *= 255;
a *= 255;
}
return Color.argb((int) a, (int) r, (int) g, (int) b);
}
示例4: valueFromObject
import android.util.JsonReader; //導入方法依賴的package包/類
static float valueFromObject(JsonReader reader) throws IOException {
JsonToken token = reader.peek();
switch (token) {
case NUMBER:
return (float) reader.nextDouble();
case BEGIN_ARRAY:
reader.beginArray();
float val = (float) reader.nextDouble();
while (reader.hasNext()) {
reader.skipValue();
}
reader.endArray();
return val;
default:
throw new IllegalArgumentException("Unknown value for token of type " + token);
}
}
示例5: parseFonts
import android.util.JsonReader; //導入方法依賴的package包/類
private static void parseFonts(JsonReader reader, Map<String, Font> fonts) throws IOException {
reader.beginObject();
while (reader.hasNext()) {
switch (reader.nextName()) {
case "list":
reader.beginArray();
while (reader.hasNext()) {
Font font = FontParser.parse(reader);
fonts.put(font.getName(), font);
}
reader.endArray();
break;
default:
reader.skipValue();
}
}
reader.endObject();
}
示例6: readPlaceTypesArray
import android.util.JsonReader; //導入方法依賴的package包/類
List<PlaceType> readPlaceTypesArray(JsonReader reader) throws IOException {
List<PlaceType> types = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
switch (reader.nextString()) {
case "route":
types.add(PlaceType.ROUTE);
break;
case "geocode":
types.add(PlaceType.GEOCODE);
break;
default:
reader.skipValue();
break;
}
}
reader.endArray();
return types;
}
示例7: PoemParser
import android.util.JsonReader; //導入方法依賴的package包/類
PoemParser(InputStream in, SprogDbHelper dbHelper, MarkdownConverter markdownConverter)
throws IOException {
this.markdownConverter = markdownConverter;
read_poems = dbHelper.getReadPoems();
favorite_poems = dbHelper.getFavoritePoems();
reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
mainpoem_links = new HashMap<>();
reader.beginArray();
}
示例8: readSampleGroup
import android.util.JsonReader; //導入方法依賴的package包/類
private void readSampleGroup(JsonReader reader, List<SampleGroup> groups) throws IOException {
String groupName = "";
ArrayList<Sample> samples = new ArrayList<>();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
switch (name) {
case "name":
groupName = reader.nextString();
break;
case "samples":
reader.beginArray();
while (reader.hasNext()) {
samples.add(readEntry(reader, false));
}
reader.endArray();
break;
case "offline_samples":
reader.beginArray();
while (reader.hasNext()){
samples.add(readOfflineEntry(reader));
}
reader.endArray();
break;
case "_comment":
reader.nextString(); // Ignore.
break;
default:
throw new ParserException("Unsupported name: " + name);
}
}
reader.endObject();
SampleGroup group = getGroup(groupName, groups);
group.samples.addAll(samples);
}
示例9: parsePeersArray
import android.util.JsonReader; //導入方法依賴的package包/類
private static List<Peer> parsePeersArray(JsonReader jsonReader) throws IOException {
List<Peer> result = new ArrayList<>();
jsonReader.beginArray();
try {
while (jsonReader.hasNext()) {
Peer peer = parsePeer(jsonReader);
if (peer != null) {
result.add(peer);
}
}
} finally {
jsonReader.endArray();
}
return result;
}
示例10: parsePortArray
import android.util.JsonReader; //導入方法依賴的package包/類
public static List<Port> parsePortArray(JsonReader jsonReader) throws IOException {
List<Port> inputPorts = new ArrayList<>();
jsonReader.beginArray();
while (jsonReader.hasNext()) {
inputPorts.add(new Port(jsonReader));
}
jsonReader.endArray();
return inputPorts;
}
示例11: readMessagesArray
import android.util.JsonReader; //導入方法依賴的package包/類
/**
* Iterating objects
* @param reader
* @return
* @throws IOException
*/
private ArrayList<AboutRecord> readMessagesArray(JsonReader reader) throws IOException {
ArrayList<AboutRecord> messages = new ArrayList<AboutRecord>();
reader.beginArray();
while (reader.hasNext()) {
messages.add(readMessage(reader));
}
reader.endArray();
return messages;
}
示例12: parseRecords
import android.util.JsonReader; //導入方法依賴的package包/類
private static Records parseRecords(JsonReader parser, @Nullable URI uri) throws IOException {
Records records = new Records();
parser.beginArray();
while (parser.hasNext()) {
Record record = parseRecord(parser, uri);
if (record != null) {
records.add(record);
}
}
parser.endArray();
return records;
}
示例13: parseMetadata
import android.util.JsonReader; //導入方法依賴的package包/類
/**
* Parses metadata in the JSON format.
* @param input a stream reader expected to contain JSON formatted metadata.
* @return dictionary metadata, as an array of WordListMetadata objects.
* @throws IOException if the underlying reader throws IOException during reading.
* @throws BadFormatException if the data was not in the expected format.
*/
public static List<WordListMetadata> parseMetadata(final InputStreamReader input)
throws IOException, BadFormatException {
JsonReader reader = new JsonReader(input);
final ArrayList<WordListMetadata> readInfo = new ArrayList<>();
reader.beginArray();
while (reader.hasNext()) {
final WordListMetadata thisMetadata = parseOneWordList(reader);
if (!TextUtils.isEmpty(thisMetadata.mLocale))
readInfo.add(thisMetadata);
}
return Collections.unmodifiableList(readInfo);
}
示例14: processResponseRecoItem
import android.util.JsonReader; //導入方法依賴的package包/類
private void processResponseRecoItem(JsonReader reader, List<RecommendationProduct> recommendations) throws IOException {
String title = null, id = null;
Map<String, RecommendationProductValue> recommendationValues = new HashMap<>();
reader.beginArray();//begin array of one recommendation
while (reader.hasNext())
{
String value = null, identifier = null, type = null;
reader.beginObject(); //read recommendation item
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("value"))
value = reader.nextString();
else if (name.equals("identifier"))
identifier = reader.nextString();
else if (name.equals("type"))
type = reader.nextString();
else
reader.skipValue();
}
reader.endObject();
if (identifier.equals("id"))
id = value;
else if(identifier.equals("campaignTitle"))
title = value;
else
recommendationValues.put(identifier, new RecommendationProductValue(type, value));
}
reader.endArray();
if (id != null)
recommendations.add(new RecommendationProduct(id, title, recommendationValues));
else
{
WebtrekkLogging.log("Incorrect recommendation. Lack of id. Title:"+title);
}
}
示例15: extractSite
import android.util.JsonReader; //導入方法依賴的package包/類
private static void extractSite(final JsonReader reader, final UrlListCallback callback) throws IOException {
reader.beginObject();
final String siteOwner = reader.nextName();
{
reader.beginObject();
while (reader.hasNext()) {
// We can get the site name using reader.nextName() here:
reader.skipValue();
JsonToken nextToken = reader.peek();
if (nextToken.name().equals("STRING")) {
// Sometimes there's a "dnt" entry, with unspecified purpose.
reader.skipValue();
} else {
reader.beginArray();
while (reader.hasNext()) {
final String blockURL = reader.nextString();
callback.put(blockURL, siteOwner);
}
reader.endArray();
}
}
reader.endObject();
}
reader.endObject();
}