Search in sources :

Example 21 with JSONObject

use of org.json.JSONObject in project glide by bumptech.

the class PhotoJsonStringParser method parse.

List<Photo> parse(String response) throws JSONException {
    JSONObject searchResults = new JSONObject(response.substring(FLICKR_API_PREFIX_LENGTH, response.length() - 1));
    JSONArray photos = searchResults.getJSONObject("photos").getJSONArray("photo");
    List<Photo> results = new ArrayList<>(photos.length());
    for (int i = 0, size = photos.length(); i < size; i++) {
        results.add(new Photo(photos.getJSONObject(i)));
    }
    return results;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList)

Example 22 with JSONObject

use of org.json.JSONObject in project clutchandroid by clutchio.

the class ClutchStats method testFailure.

public void testFailure(String name, String type) {
    JSONObject data = new JSONObject();
    try {
        data.put("action", "failure");
        data.put("name", name);
        data.put("type", type);
    } catch (JSONException e) {
        Log.e(TAG, "Could not create JSON for insert into testFailure (name: " + name + ", type: " + type + ")");
        return;
    }
    logABData(data);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 23 with JSONObject

use of org.json.JSONObject in project clutchandroid by clutchio.

the class ClutchStats method logAction.

public void logAction(String action, Map<String, ?> data) {
    SQLiteDatabase db = getWritableDatabase();
    Object[] args = { ClutchUtils.getUUID(), System.currentTimeMillis() / 1000.0, action, new JSONObject(data).toString() };
    db.execSQL("INSERT INTO stats (uuid, ts, action, data) VALUES (?, ?, ?, ?)", args);
    db.close();
}
Also used : JSONObject(org.json.JSONObject) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) JSONObject(org.json.JSONObject)

Example 24 with JSONObject

use of org.json.JSONObject in project clutchandroid by clutchio.

the class ClutchStats method goalReached.

public void goalReached(String name) {
    JSONObject data = new JSONObject();
    try {
        data.put("action", "goal");
        data.put("name", name);
    } catch (JSONException e) {
        Log.e(TAG, "Could not create JSON for insert into goalReached (name: " + name + ")");
        return;
    }
    logABData(data);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 25 with JSONObject

use of org.json.JSONObject in project clutchandroid by clutchio.

the class ClutchStats method testChosen.

public void testChosen(String name, int choice, int numChoices) {
    JSONObject data = new JSONObject();
    try {
        data.put("action", "test");
        data.put("name", name);
        data.put("choice", choice);
        data.put("num_choices", numChoices);
    } catch (JSONException e) {
        Log.e(TAG, "Could not create JSON for insert into testChosen (name: " + name + ", choice: " + choice + ", numChoies: " + numChoices + ")");
        return;
    }
    logABData(data);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Aggregations

JSONObject (org.json.JSONObject)3855 JSONException (org.json.JSONException)1520 JSONArray (org.json.JSONArray)1084 Test (org.junit.Test)494 IOException (java.io.IOException)425 ArrayList (java.util.ArrayList)375 HashMap (java.util.HashMap)282 Test (org.testng.annotations.Test)173 File (java.io.File)137 Date (java.util.Date)137 ServiceException (org.b3log.latke.service.ServiceException)125 VolleyError (com.android.volley.VolleyError)103 Bundle (android.os.Bundle)102 Map (java.util.Map)95 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)92 InputStreamReader (java.io.InputStreamReader)84 Response (com.android.volley.Response)83 BufferedReader (java.io.BufferedReader)83 List (java.util.List)76 InputStream (java.io.InputStream)70