Search in sources :

Example 6 with JSONException

use of org.json.JSONException 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 7 with JSONException

use of org.json.JSONException 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 8 with JSONException

use of org.json.JSONException 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)

Example 9 with JSONException

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

the class ClutchStats method getABLogs.

public ArrayList<ABRow> getABLogs() {
    SQLiteDatabase db = getReadableDatabase();
    String[] args = {};
    ArrayList<ABRow> res = new ArrayList<ABRow>();
    Cursor cur = db.rawQuery("SELECT uuid, ts, data FROM ablog ORDER BY ts", args);
    cur.moveToFirst();
    while (!cur.isAfterLast()) {
        String uuid = cur.getString(0);
        double ts = cur.getDouble(1);
        JSONObject data;
        try {
            data = new JSONObject(cur.getString(2));
        } catch (JSONException e) {
            Log.w(TAG, "Could not serialize to JSON: " + cur.getString(3));
            cur.moveToNext();
            continue;
        }
        res.add(new ABRow(uuid, ts, data));
        cur.moveToNext();
    }
    db.close();
    return res;
}
Also used : JSONObject(org.json.JSONObject) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Example 10 with JSONException

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

the class ClutchStats method setNumChoices.

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

Aggregations

JSONException (org.json.JSONException)1760 JSONObject (org.json.JSONObject)1346 JSONArray (org.json.JSONArray)593 IOException (java.io.IOException)315 ArrayList (java.util.ArrayList)194 HashMap (java.util.HashMap)139 Test (org.junit.Test)108 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)98 Bundle (android.os.Bundle)67 VolleyError (com.android.volley.VolleyError)66 File (java.io.File)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)62 Response (com.android.volley.Response)58 URL (java.net.URL)54 Map (java.util.Map)45 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 MalformedURLException (java.net.MalformedURLException)43 UnsupportedEncodingException (java.io.UnsupportedEncodingException)41 Intent (android.content.Intent)40 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)40