當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonReader類代碼示例

本文整理匯總了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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:22,代碼來源:SearchMovieParser.java

示例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;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:22,代碼來源:PeerListParser.java

示例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();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:Realm.java

示例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;
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:21,代碼來源:SampleChooserActivity.java

示例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;
}
 
開發者ID:hortonworks,項目名稱:nifi-android-s2s,代碼行數:19,代碼來源:Port.java

示例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;
}
 
開發者ID:RomascuAndrei,項目名稱:BTNotifierAndroid,代碼行數:21,代碼來源:IncomingMessage.java

示例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;
}
 
開發者ID:HTBridge,項目名稱:pivaa,代碼行數:22,代碼來源:AboutJSONParser.java

示例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);
}
 
開發者ID:HTBridge,項目名稱:pivaa,代碼行數:28,代碼來源:AboutJSONParser.java

示例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;
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:18,代碼來源:BlocklistProcessor.java

示例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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:17,代碼來源:MovieIdParser.java

示例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();
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:18,代碼來源:MovieIdParser.java

示例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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:22,代碼來源:MovieIdParser.java

示例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);
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:21,代碼來源:MovieIdParser.java

示例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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:24,代碼來源:MovieIdParser.java

示例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;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:27,代碼來源:MovieIdImageParser.java


注:本文中的android.util.JsonReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。