Search in sources :

Example 6 with CrashReportData

use of org.acra.collector.CrashReportData in project acra by ACRA.

the class JsonUtils method toCrashReportData.

public static CrashReportData toCrashReportData(JSONObject json) {
    CrashReportData data = new CrashReportData();
    for (Iterator<String> iterator = json.keys(); iterator.hasNext(); ) {
        String key = iterator.next();
        try {
            ReportField field = ReportField.valueOf(key);
            Object value = json.get(key);
            if (value instanceof JSONObject) {
                data.put(field, new ComplexElement((JSONObject) value));
            } else if (value instanceof Number) {
                data.putNumber(field, (Number) value);
            } else if (value instanceof Boolean) {
                data.putBoolean(field, (Boolean) value);
            } else {
                data.putString(field, value.toString());
            }
        } catch (IllegalArgumentException e) {
            Log.w(LOG_TAG, "Unknown report key " + key, e);
        } catch (JSONException e) {
            Log.w(LOG_TAG, "Unable to read report field " + key, e);
        }
    }
    return data;
}
Also used : CrashReportData(org.acra.collector.CrashReportData) ReportField(org.acra.ReportField) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ComplexElement(org.acra.model.ComplexElement)

Aggregations

CrashReportData (org.acra.collector.CrashReportData)6 JSONException (org.json.JSONException)4 CrashReportPersister (org.acra.file.CrashReportPersister)3 File (java.io.File)2 IOException (java.io.IOException)2 ReportField (org.acra.ReportField)2 ComplexElement (org.acra.model.ComplexElement)2 SharedPreferences (android.content.SharedPreferences)1 NonNull (android.support.annotation.NonNull)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 ReportingInteractionMode (org.acra.ReportingInteractionMode)1 ReportLocator (org.acra.file.ReportLocator)1 BooleanElement (org.acra.model.BooleanElement)1 Element (org.acra.model.Element)1 NumberElement (org.acra.model.NumberElement)1