Search in sources :

Example 11 with JsonReader

use of android.util.JsonReader in project android_frameworks_base by crdroidandroid.

the class StatementParser method parseStatement.

/**
     * Parses a single JSON statement.
     */
static ParsedStatement parseStatement(String statementString, AbstractAsset source) throws AssociationServiceException, IOException, JSONException {
    JsonReader reader = new JsonReader(new StringReader(statementString));
    reader.setLenient(false);
    return parseStatement(reader, source);
}
Also used : StringReader(java.io.StringReader) JsonReader(android.util.JsonReader)

Example 12 with JsonReader

use of android.util.JsonReader in project android_frameworks_base by AOSPA.

the class AbstractAsset method create.

/**
     * Creates a new Asset from its JSON string representation.
     *
     * @throws AssociationServiceException if the assetJson is not well formatted.
     */
public static AbstractAsset create(String assetJson) throws AssociationServiceException {
    JsonReader reader = new JsonReader(new StringReader(assetJson));
    reader.setLenient(false);
    try {
        return AssetFactory.create(JsonParser.parse(reader));
    } catch (JSONException | IOException e) {
        throw new AssociationServiceException("Input is not a well formatted asset descriptor.", e);
    }
}
Also used : StringReader(java.io.StringReader) JsonReader(android.util.JsonReader) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 13 with JsonReader

use of android.util.JsonReader in project android_frameworks_base by AOSPA.

the class StatementParser method parseStatementList.

/**
     * Parses a JSON array of statements.
     */
static ParsedStatement parseStatementList(String statementList, AbstractAsset source) throws JSONException, IOException {
    List<Statement> statements = new ArrayList<Statement>();
    List<String> delegates = new ArrayList<String>();
    JsonReader reader = new JsonReader(new StringReader(statementList));
    reader.setLenient(false);
    reader.beginArray();
    while (reader.hasNext()) {
        ParsedStatement result;
        try {
            result = parseStatement(reader, source);
        } catch (AssociationServiceException e) {
            // The element in the array is well formatted Json but not a well-formed Statement.
            continue;
        }
        statements.addAll(result.getStatements());
        delegates.addAll(result.getDelegates());
    }
    reader.endArray();
    return new ParsedStatement(statements, delegates);
}
Also used : ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) JsonReader(android.util.JsonReader)

Example 14 with JsonReader

use of android.util.JsonReader in project android_frameworks_base by AOSPA.

the class StatementParser method parseStatement.

/**
     * Parses a single JSON statement.
     */
static ParsedStatement parseStatement(String statementString, AbstractAsset source) throws AssociationServiceException, IOException, JSONException {
    JsonReader reader = new JsonReader(new StringReader(statementString));
    reader.setLenient(false);
    return parseStatement(reader, source);
}
Also used : StringReader(java.io.StringReader) JsonReader(android.util.JsonReader)

Example 15 with JsonReader

use of android.util.JsonReader in project android_frameworks_base by DirtyUnicorns.

the class StatementParser method parseStatementList.

/**
     * Parses a JSON array of statements.
     */
static ParsedStatement parseStatementList(String statementList, AbstractAsset source) throws JSONException, IOException {
    List<Statement> statements = new ArrayList<Statement>();
    List<String> delegates = new ArrayList<String>();
    JsonReader reader = new JsonReader(new StringReader(statementList));
    reader.setLenient(false);
    reader.beginArray();
    while (reader.hasNext()) {
        ParsedStatement result;
        try {
            result = parseStatement(reader, source);
        } catch (AssociationServiceException e) {
            // The element in the array is well formatted Json but not a well-formed Statement.
            continue;
        }
        statements.addAll(result.getStatements());
        delegates.addAll(result.getDelegates());
    }
    reader.endArray();
    return new ParsedStatement(statements, delegates);
}
Also used : ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) JsonReader(android.util.JsonReader)

Aggregations

JsonReader (android.util.JsonReader)26 StringReader (java.io.StringReader)18 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 JSONException (org.json.JSONException)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 TargetApi (android.annotation.TargetApi)2 InputStreamReader (java.io.InputStreamReader)2 SuppressLint (android.annotation.SuppressLint)1 Uri (android.net.Uri)1 RealmException (io.realm.exceptions.RealmException)1 Table (io.realm.internal.Table)1 Scanner (java.util.Scanner)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1