本文整理匯總了Java中android.util.JsonReader類的典型用法代碼示例。如果您正苦於以下問題:Java JsonReader類的具體用法?Java JsonReader怎麽用?Java JsonReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JsonReader類屬於android.util包,在下文中一共展示了JsonReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readResult
import android.util.JsonReader; //導入依賴的package包/類
public static SearchResult readResult(JsonReader reader) throws IOException {
SearchResult item = new SearchResult();
reader.beginObject();
String name;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_TITLE:
item.setTitle(reader.nextString());
break;
case KEY_ID:
item.setId(reader.nextInt());
break;
default:
reader.skipValue();
}
}
reader.endObject();
return item;
}
示例2: parsePeers
import android.util.JsonReader; //導入依賴的package包/類
public static List<Peer> parsePeers(InputStream inputStream) throws IOException {
List<Peer> result = null;
JsonReader jsonReader = new JsonReader(new InputStreamReader(inputStream, Charsets.UTF_8));
try {
jsonReader.beginObject();
try {
while (jsonReader.hasNext()) {
if (PEERS.equals(jsonReader.nextName())) {
result = parsePeersArray(jsonReader);
} else {
jsonReader.skipValue();
}
}
} finally {
jsonReader.endObject();
}
} finally {
jsonReader.close();
}
return result == null ? Collections.<Peer>emptyList() : result;
}
示例3: 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();
}
}
示例4: doInBackground
import android.util.JsonReader; //導入依賴的package包/類
@Override
protected List<SampleGroup> doInBackground(String... uris) {
List<SampleGroup> result = new ArrayList<>();
Context context = getApplicationContext();
String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
for (String uri : uris) {
DataSpec dataSpec = new DataSpec(Uri.parse(uri));
InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
try {
readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
} catch (Exception e) {
Log.e(TAG, "Error loading sample list: " + uri, e);
sawError = true;
} finally {
Util.closeQuietly(dataSource);
}
}
return result;
}
示例5: Port
import android.util.JsonReader; //導入依賴的package包/類
public Port(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
String id = null;
String name = null;
while (jsonReader.hasNext()) {
String key = jsonReader.nextName();
if (id == null && ID.equals(key)) {
id = jsonReader.nextString();
} else if (name == null && NAME.equals(key)) {
name = jsonReader.nextString();
} else {
jsonReader.skipValue();
}
}
jsonReader.endObject();
this.id = id;
this.name = name;
}
示例6: IncomingMessage
import android.util.JsonReader; //導入依賴的package包/類
public IncomingMessage(String message) throws IOException {
JsonReader reader = new JsonReader(new StringReader(message));
reader.beginObject();
if (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("event")) {
String typeString = reader.nextString();
if (typeString.equals("action")) {
eventType = EventType.ACTION;
} else if (typeString.equals("dismiss")) {
eventType = EventType.DISMISS;
} else if (typeString.equals("blacklist")) {
eventType = EventType.BLACKLIST;
} else if (typeString.equals("sms")) {
eventType = EventType.SMS;
}
}
}
jsonReader = reader;
}
示例7: readJsonStream
import android.util.JsonReader; //導入依賴的package包/類
/**
* Reading JSON stream from InputStream
* @param in
* @return
* @throws IOException
*/
private ArrayList<AboutRecord> readJsonStream(InputStream in) {
try {
JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
try {
return readMessagesArray(reader);
} finally {
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<AboutRecord> list = new ArrayList<AboutRecord>();
return list;
}
示例8: readMessage
import android.util.JsonReader; //導入依賴的package包/類
/**
* Paring object
* @param reader
* @return
* @throws IOException
*/
private AboutRecord readMessage(JsonReader reader) throws IOException {
String name = "";
String description = "";
reader.beginObject();
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("name")) {
name = reader.nextString();
} else if (key.equals("description")) {
description = reader.nextString();
} else {
reader.skipValue();
}
}
reader.endObject();
return new AboutRecord(name, description);
}
示例9: loadCategoryMap
import android.util.JsonReader; //導入依賴的package包/類
public static Map<String, Trie> loadCategoryMap(final JsonReader reader, final Map<String, Trie> categoryMap, final ListType listType) throws IOException {
reader.beginObject();
while (reader.hasNext()) {
final String name = reader.nextName();
if (name.equals("categories")) {
extractCategories(reader, categoryMap, listType);
} else {
reader.skipValue();
}
}
reader.endObject();
return categoryMap;
}
示例10: readName
import android.util.JsonReader; //導入依賴的package包/類
private static String readName(JsonReader reader) throws IOException {
reader.beginObject();
String name;
String returnValue = null;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_NAME:
returnValue = reader.nextString();
break;
default:
reader.skipValue();
}
}
reader.endObject();
return returnValue;
}
示例11: readCasts
import android.util.JsonReader; //導入依賴的package包/類
private static void readCasts(JsonReader reader, MovieTags target) throws IOException {
reader.beginObject();
String name;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_CAST:
readActors(reader, target);
break;
case KEY_CREW:
readDirectors(reader, target);
break;
default:
reader.skipValue();
}
}
reader.endObject();
}
示例12: readDirector
import android.util.JsonReader; //導入依賴的package包/類
private static String readDirector(JsonReader reader) throws IOException {
reader.beginObject();
String name;
String personName = null;
boolean isDirector = false;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_NAME:
personName = reader.nextString();
break;
case KEY_JOB:
if (DIRECTOR.equals(reader.nextString()))
isDirector = true;
break;
default:
reader.skipValue();
}
}
reader.endObject();
return isDirector ? personName : null;
}
示例13: readActor
import android.util.JsonReader; //導入依賴的package包/類
private static void readActor(JsonReader reader, MovieTags target) throws IOException {
reader.beginObject();
String name;
String personName = null;
String personRole = null;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_NAME:
personName = reader.nextString();
break;
case KEY_CHARACTER:
personRole = reader.nextString();
break;
default:
reader.skipValue();
}
}
reader.endObject();
target.addActorIfAbsent(personName, personRole);
}
示例14: readCountry
import android.util.JsonReader; //導入依賴的package包/類
private static String readCountry(JsonReader reader) throws IOException {
String certification = null;
boolean isUS = false;
reader.beginObject();
String name;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_CERTIFICATION:
certification = reader.nextString();
break;
case KEY_ISO_3166:
if (COUNTRY_US.equals(reader.nextString()))
isUS = true;
break;
default:
reader.skipValue();
}
}
reader.endObject();
return isUS ? certification : null;
}
示例15: getResult
import android.util.JsonReader; //導入依賴的package包/類
@Override
protected MovieIdImagesResult getResult(JsonReader reader, String config) throws IOException {
MovieIdImagesResult myResult = new MovieIdImagesResult();
LinkedList<Image> posters = new LinkedList<Image>();
LinkedList<Image> backdrops = new LinkedList<Image>();
reader.beginObject();
String name;
while ((name = getNextNotNullName(reader)) != null) {
switch(MATCHER.match(name)) {
case KEY_POSTERS:
readImages(reader, posters, config);
break;
case KEY_BACKDROPS:
readImages(reader, backdrops, config);
break;
default:
reader.skipValue();
}
}
reader.endObject();
myResult.posterPaths = getSortedPaths(posters);
myResult.backdropPaths = getSortedPaths(backdrops);
return myResult;
}