Search in sources :

Example 16 with JSONException

use of org.json.JSONException in project SimplifyReader by chentao0707.

the class DownloadInfo method toJSONObject.

public JSONObject toJSONObject() {
    JSONObject o = new JSONObject();
    try {
        o.put(KEY_title, title);
        o.put(KEY_vid, videoid);
        o.put(KEY_showid, showid);
        o.put(KEY_showname, showname);
        o.put(KEY_format, format);
        o.put(KEY_show_videoseq, show_videoseq);
        o.put(KEY_showepisode_total, showepisode_total);
        o.put(KEY_cats, cats);
        o.put(KEY_seconds, seconds);
        o.put(KEY_size, size);
        o.put(KEY_segcount, segCount);
        o.put(KEY_segsseconds, PlayerUtil.join(segsSeconds));
        o.put(KEY_segssize, PlayerUtil.join(segsSize));
        o.put(KEY_taskid, taskId);
        o.put(KEY_downloadedsize, downloadedSize);
        o.put(KEY_segdownloadedsize, segDownloadedSize);
        o.put(KEY_segID, segId);
        o.put(KEY_createtime, createTime);
        o.put(KEY_starttime, startTime);
        o.put(KEY_getUrlTime, getUrlTime);
        o.put(KEY_finishtime, finishTime);
        // o.put(KEY_segsUrl, YoukuUtil.join(segsUrl));
        o.put(KEY_state, state);
        o.put(KEY_exceptionid, exceptionId);
        o.put(KEY_progress, progress);
        o.put(KEY_language, language);
        o.put(KEY_playTime, playTime);
        o.put(KEY_lastPlayTime, lastPlayTime);
        o.put(KEY_savepath, savePath);
    } catch (JSONException e) {
        Logger.e("toJSONObject", e);
        o = null;
    }
    return o;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 17 with JSONException

use of org.json.JSONException in project AnimeTaste by daimajia.

the class Animation method build.

/**
     * 通过JSONObject开始构建Animation对象,大量数据时,只能在线程中执行
     *
     * @param object Animation JsonObject
     * @return Animation对象
     */
public static Animation build(JSONObject object) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        Throwable warn = new Throwable("Please do not execute Animation.build(JSONObject object) " + "in Main thread, it's bad performance and may block the ui thread");
        throw new RuntimeException(warn);
    }
    int id = Integer.valueOf(getValue(object, "Id"));
    String name = getValue(object, "Name");
    String originVideoUrl = getValue(object, "VideoUrl");
    String author = getValue(object, "Author");
    String year = getValue(object, "Year");
    String brief = getValue(object, "Brief");
    String homePic = getValue(object, "HomePic");
    String detailPic = getValue(object, "DetailPic");
    Boolean isFav = false;
    String uhd = EMPTY, hd = EMPTY, sd = EMPTY;
    boolean isWatched = false;
    try {
        isWatched = new Select().from(WatchRecord.class).where("aid=?", id).executeSingle() != null;
        isFav = new Select().from(Animation.class).where("AnimationId='" + id + "' AND IsFavorite='1'").executeSingle() != null;
        JSONObject videoSourceObject = object.getJSONObject("VideoSource");
        uhd = videoSourceObject.has("uhd") ? videoSourceObject.getString("uhd") : EMPTY;
        hd = videoSourceObject.has("hd") ? videoSourceObject.getString("hd") : EMPTY;
        sd = videoSourceObject.has("sd") ? videoSourceObject.getString("sd") : EMPTY;
        uhd = uhd.replace(";", "&");
        hd = uhd.replace(";", "&");
        sd = uhd.replace(";", "&");
    } catch (JSONException ignored) {
    } finally {
        return new Animation(id, name, originVideoUrl, author, year, brief, homePic, detailPic, uhd, hd, sd, isFav, isWatched);
    }
}
Also used : JSONObject(org.json.JSONObject) Select(com.activeandroid.query.Select) JSONException(org.json.JSONException)

Example 18 with JSONException

use of org.json.JSONException in project android by cSploit.

the class GitHubParser method getReleaseBody.

public synchronized String getReleaseBody(String tag_name) throws JSONException, IOException {
    JSONObject release;
    String current;
    if (mReleases == null)
        fetchReleases();
    for (int i = 0; i < mReleases.length(); i++) {
        release = mReleases.getJSONObject(i);
        current = release.getString("tag_name");
        if (current.equals(tag_name) || current.equals("v" + tag_name))
            return release.getString("body");
    }
    throw new JSONException(String.format("release '%s' not found", tag_name));
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 19 with JSONException

use of org.json.JSONException in project flux by eclipse.

the class Utils method editsToJsonArray.

public static JSONArray editsToJsonArray(TextEdit edit) {
    final LinkedList<JSONObject> list = new LinkedList<JSONObject>();
    edit.accept(new TextEditVisitor() {

        @Override
        public boolean visit(DeleteEdit delete) {
            try {
                JSONObject json = new JSONObject();
                json.put("offset", delete.getOffset());
                json.put("length", delete.getLength());
                json.put("text", "");
                list.addFirst(json);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return super.visit(delete);
        }

        @Override
        public boolean visit(InsertEdit insert) {
            try {
                JSONObject json = new JSONObject();
                json.put("offset", insert.getOffset());
                json.put("length", 0);
                json.put("text", insert.getText());
                list.addFirst(json);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return super.visit(insert);
        }

        @Override
        public boolean visit(ReplaceEdit replace) {
            try {
                JSONObject json = new JSONObject();
                json.put("offset", replace.getOffset());
                json.put("length", replace.getLength());
                json.put("text", replace.getText());
                list.addFirst(json);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return super.visit(replace);
        }
    });
    return new JSONArray(list);
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) JSONObject(org.json.JSONObject) TextEditVisitor(org.eclipse.text.edits.TextEditVisitor) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) DeleteEdit(org.eclipse.text.edits.DeleteEdit) LinkedList(java.util.LinkedList)

Example 20 with JSONException

use of org.json.JSONException in project flux by eclipse.

the class RenameService method computeReferences.

public JSONArray computeReferences(String username, String resourcePath, int offset, int length) {
    try {
        ICompilationUnit unit = liveEditUnits.getLiveEditUnit(username, resourcePath);
        if (unit != null) {
            final ASTParser parser = ASTParser.newParser(AST.JLS4);
            // Parse the class as a compilation unit.
            parser.setKind(ASTParser.K_COMPILATION_UNIT);
            parser.setSource(unit);
            parser.setResolveBindings(true);
            // Return the compiled class as a compilation unit
            final ASTNode compilationUnit = parser.createAST(null);
            final ASTNode nameNode = NodeFinder.perform(compilationUnit, offset, length);
            final List<ASTNode> nodes = new ArrayList<ASTNode>();
            if (nameNode instanceof SimpleName) {
                compilationUnit.accept(new ASTVisitor() {

                    @Override
                    public boolean visit(SimpleName node) {
                        if (node.getIdentifier().equals(((SimpleName) nameNode).getIdentifier())) {
                            nodes.add(node);
                        }
                        return super.visit(node);
                    }
                });
            }
            JSONArray references = new JSONArray();
            for (ASTNode astNode : nodes) {
                JSONObject nodeObject = new JSONObject();
                nodeObject.put("offset", astNode.getStartPosition());
                nodeObject.put("length", astNode.getLength());
                references.put(nodeObject);
            }
            return references;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JSONObject(org.json.JSONObject) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ASTParser(org.eclipse.jdt.core.dom.ASTParser) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

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