Search in sources :

Example 21 with JsonReader

use of android.util.JsonReader in project DrupalCloud by INsReady.

the class RESTServerClient method userLogin.

/*
	 * public boolean flagFlag(String flagName, int contentId, int uid, boolean
	 * action, boolean skipPermissionCheck) throws ServiceNotAvailableException
	 * { String uri = mENDPOIN + "flag/flag"; BasicNameValuePair[] parameters =
	 * new BasicNameValuePair[5]; parameters[0] = new
	 * BasicNameValuePair("flag_name", flagName); parameters[1] = new
	 * BasicNameValuePair("content_id", String.valueOf(contentId));
	 * parameters[2] = new BasicNameValuePair("uid", String.valueOf(uid));
	 * String actionName = (action) ? "flag" : "unflag"; parameters[3] = new
	 * BasicNameValuePair("action", actionName); String skipPermissionCheckName
	 * = (skipPermissionCheck) ? "TRUE" : "FALSE"; parameters[4] = new
	 * BasicNameValuePair("skip_permission_check", skipPermissionCheckName);
	 * //String result = call(uri, parameters); JSONObject jso; try { jso = new
	 * JSONObject(result); boolean flag = jso.getBoolean("#data"); return flag;
	 * } catch (JSONException e) { e.printStackTrace(); } return false; }
	 */
/*
	 * public boolean flagIsFlagged(String flagName, int contentId, int uid)
	 * throws ServiceNotAvailableException { String uri = mENDPOIN +
	 * "flag/flag_isflaged"; BasicNameValuePair[] parameters = new
	 * BasicNameValuePair[3]; parameters[0] = new
	 * BasicNameValuePair("flag_name", flagName); parameters[1] = new
	 * BasicNameValuePair("content_id", String.valueOf(contentId));
	 * parameters[2] = new BasicNameValuePair("uid", String.valueOf(uid));
	 * String result = call(uri, parameters);
	 * 
	 * JSONObject jso; try { jso = new JSONObject(result); boolean flag =
	 * jso.getBoolean(""); return flag; } catch (JSONException e) {
	 * e.printStackTrace(); } return false; }
	 */
public JsonReader userLogin(String username, String password) throws ServiceNotAvailableException, IOException {
    String uri = mENDPOIN + "user/login";
    BasicNameValuePair[] parameters = new BasicNameValuePair[2];
    parameters[0] = new BasicNameValuePair("username", username);
    parameters[1] = new BasicNameValuePair("password", password);
    JsonReader jsr = new JsonReader(callPost(uri, parameters));
    return jsr;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JsonReader(android.util.JsonReader)

Example 22 with JsonReader

use of android.util.JsonReader in project platform_frameworks_base by android.

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 23 with JsonReader

use of android.util.JsonReader in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class MetadataParser method parseMetadata.

/**
     * 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);
}
Also used : ArrayList(java.util.ArrayList) JsonReader(android.util.JsonReader)

Example 24 with JsonReader

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

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 25 with JsonReader

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

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)

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