Example usage for org.json JSONException toString

List of usage examples for org.json JSONException toString

Introduction

In this page you can find the example usage for org.json JSONException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:cn.code.notes.gtask.data.Task.java

public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {//www  .  jav a  2 s  .c  o m
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

            // notes
            if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
                setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
            }

            // deleted
            if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
                setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
            }

            // completed
            if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
                setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get task content from jsonobject");
        }
    }
}

From source file:cn.code.notes.gtask.data.Task.java

public void setContentByLocalJSON(JSONObject js) {
    if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
        Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
    }/*  w w  w.j a va 2 s  . co m*/

    try {
        JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
        JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

        if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
            Log.e(TAG, "invalid type");
            return;
        }

        for (int i = 0; i < dataArray.length(); i++) {
            JSONObject data = dataArray.getJSONObject(i);
            if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                setName(data.getString(DataColumns.CONTENT));
                break;
            }
        }

    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }
}

From source file:cn.code.notes.gtask.data.Task.java

public JSONObject getLocalJSONFromContent() {
    String name = getName();/*  w  ww.  j av a 2  s.  co  m*/
    try {
        if (mMetaInfo == null) {
            // new task created from web
            if (name == null) {
                Log.w(TAG, "the note seems to be an empty one");
                return null;
            }

            JSONObject js = new JSONObject();
            JSONObject note = new JSONObject();
            JSONArray dataArray = new JSONArray();
            JSONObject data = new JSONObject();
            data.put(DataColumns.CONTENT, name);
            dataArray.put(data);
            js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            js.put(GTaskStringUtils.META_HEAD_NOTE, note);
            return js;
        } else {
            // synced task
            JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
            JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject data = dataArray.getJSONObject(i);
                if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                    data.put(DataColumns.CONTENT, getName());
                    break;
                }
            }

            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            return mMetaInfo;
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        return null;
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of Japanese Keb.
 * /* ww w  .  j a v a2  s.  c o m*/
 * @param jsonString - JSON string to be parsed
 */
public void parseJapaneseKeb(String jsonString) {
    if (jsonString != null) {
        List<String> japKeb;
        JSONArray language_senses;
        try {
            language_senses = new JSONArray(jsonString);
        } catch (JSONException e) {
            Log.w(LOG_TAG, "getting parseJapaneseKeb()  initial expression failed: " + e.toString());
            return;
        }
        japKeb = this.parseOneSense(language_senses);
        for (String str : japKeb) {
            this.addJapKeb(str);
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of Japanese Reb.
 * /*w  w w.ja v a 2 s.  c o m*/
 * @param jsonString - JSON string to be parsed
 */
public void parseJapaneseReb(String jsonString) {
    if (jsonString != null) {
        List<String> japReb;
        JSONArray language_senses;
        try {
            language_senses = new JSONArray(jsonString);
        } catch (JSONException e) {
            Log.w(LOG_TAG, "getting parseJapaneseReb()  initial expression failed: " + e.toString());
            return;
        }
        japReb = this.parseOneSense(language_senses);
        for (String str : japReb) {
            this.addJapReb(str);
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Universal private function for parsing one JSONArray sense
 * /*from w  ww  .j a va  2  s. co  m*/
 * @param sense  JSONArray which should be parset to sense
 * @return List<String> returns list of parsed senses
 */
private List<String> parseOneSense(JSONArray sense) {
    if (sense == null) {
        return null;
    }
    List<String> senseTranslation = new ArrayList<String>();
    for (int k = 0; k < sense.length(); k++) {
        String oneSense;
        try {
            oneSense = sense.getString(k);
            senseTranslation.add(oneSense);
        } catch (JSONException e) {
            Log.w(LOG_TAG, "getting parseOneSense() expression failed: " + e.toString());
            e.printStackTrace();
        }
    }
    return senseTranslation;
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of English meanings.
 * /*from w w  w  .jav  a 2s  .co m*/
 * @param jsonString - JSON string to be parsed
 */
public void parseEnglish(String jsonString) {
    if (jsonString == null) {
        return;
    }
    JSONArray language_senses;
    try {
        language_senses = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "getting parseEnglish()  initial expression failed: " + e.toString());
        return;
    }

    for (int j = 0; j < language_senses.length(); j++) {
        if (!language_senses.isNull(j)) {
            List<String> sense;
            try {
                sense = parseOneSense(language_senses.getJSONArray(j));
                this.addEnglishSense(sense);
            } catch (JSONException e) {
                Log.w(LOG_TAG, "getting parseEnglish() expression failed: " + e.toString());
            }
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of Dutch meanings.
 * //  w ww. j a  v  a  2s .  c  om
 * @param jsonString - JSON string to be parsed
 */
public void parseDutch(String jsonString) {
    if (jsonString == null) {
        return;
    }
    JSONArray language_senses;
    try {
        language_senses = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "getting parseDutch()  initial expression failed: " + e.toString());
        return;
    }

    for (int j = 0; j < language_senses.length(); j++) {
        if (!language_senses.isNull(j)) {
            List<String> sense;
            try {
                sense = parseOneSense(language_senses.getJSONArray(j));
                this.addDutchSense(sense);
            } catch (JSONException e) {
                Log.w(LOG_TAG, "getting parseDutch() expression failed: " + e.toString());
            }
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of French meanings.
 * //from   w w  w  .jav a2  s .  c  o  m
 * @param jsonString - JSON string to be parsed
 */
public void parseFrench(String jsonString) {
    if (jsonString == null) {
        return;
    }
    JSONArray language_senses;
    try {
        language_senses = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "getting parseFrench()  initial expression failed: " + e.toString());
        return;
    }

    for (int j = 0; j < language_senses.length(); j++) {
        if (!language_senses.isNull(j)) {
            List<String> sense;
            try {
                sense = parseOneSense(language_senses.getJSONArray(j));
                this.addFrenchSense(sense);
            } catch (JSONException e) {
                Log.w(LOG_TAG, "getting parseFrench() expression failed: " + e.toString());
            }
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.entity.Translation.java

/**
 * Takes json string and parses it list of German meanings.
 * /* w  ww.  j av  a  2s  .c  om*/
 * @param jsonString - JSON string to be parsed
 */
public void parseGerman(String jsonString) {
    if (jsonString == null) {
        return;
    }
    JSONArray language_senses;
    try {
        language_senses = new JSONArray(jsonString);
    } catch (JSONException e) {
        Log.w(LOG_TAG, "getting parseGerman()  initial expression failed: " + e.toString());
        return;
    }

    for (int j = 0; j < language_senses.length(); j++) {
        if (!language_senses.isNull(j)) {
            List<String> sense;
            try {
                sense = parseOneSense(language_senses.getJSONArray(j));
                this.addGermanSense(sense);
            } catch (JSONException e) {
                Log.w(LOG_TAG, "getting parseGerman() expression failed: " + e.toString());
            }
        }
    }
}