Search in sources :

Example 11 with JSONArray

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

the class ClutchAB method test.

public static void test(String name, ClutchABDataTest testInstance) {
    JSONObject metaMeta = getLatestMeta();
    if (metaMeta.length() == 0) {
        stats.testFailure(name, "no-meta");
        stats.setNumChoices(name, 0, true);
        return;
    }
    JSONObject meta = metaMeta.optJSONObject(name);
    if (meta == null) {
        stats.testFailure(name, "no-meta-name");
        stats.setNumChoices(name, 0, true);
        return;
    }
    JSONArray weights = meta.optJSONArray("weights");
    JSONArray allData = meta.optJSONArray("data");
    if (allData == null || weights == null) {
        stats.testFailure(name, "no-data");
        return;
    }
    if (weights.length() == 0) {
        return;
    }
    int choice = cachedChoice(name, doubleJSONArrayToList(weights));
    stats.testChosen(name, choice, weights.length());
    if (choice == -1) {
        return;
    }
    JSONObject data = allData.optJSONObject(choice);
    testInstance.action(data);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 12 with JSONArray

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

the class LoadActivity method init.

private void init() {
    if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        Uri uri = getIntent().getData();
        if (uri == null) {
            error();
        }
        String vid = uri.getQueryParameter("vid");
        int animationId = Integer.valueOf(vid);
        ApiConnector.instance().getDetail(animationId, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, final JSONObject response) {
                super.onSuccess(statusCode, response);
                try {
                    if (statusCode == 200 && response.has("data") && response.getJSONObject("data").has("result") && response.getJSONObject("data").getBoolean("result")) {
                        final JSONObject anime = response.getJSONObject("data").getJSONObject("anime");
                        new Thread() {

                            @Override
                            public void run() {
                                super.run();
                                MobclickAgent.onEvent(mContext, "yell");
                                final Intent intent = new Intent(mContext, PlayActivity.class);
                                Animation animation = Animation.build(anime);
                                intent.putExtra("Animation", animation);
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        startActivity(intent);
                                        finish();
                                    }
                                });
                            }
                        }.start();
                    } else {
                        error();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    error();
                }
            }

            @Override
            public void onFailure(Throwable throwable, JSONArray jsonArray) {
                super.onFailure(throwable, jsonArray);
                error();
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }
        });
    } else {
        ApiConnector.instance().getInitData(20, 5, 2, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, final JSONObject response) {
                super.onSuccess(response);
                if (statusCode == 200 && response.has("data")) {
                    Message msg = Message.obtain();
                    msg.obj = response;
                    executeHandler.sendMessage(msg);
                } else {
                    error();
                }
            }

            @Override
            public void onFailure(Throwable error) {
                super.onFailure(error);
                error();
            }
        });
    }
}
Also used : Message(android.os.Message) JSONArray(org.json.JSONArray) Intent(android.content.Intent) Uri(android.net.Uri) JSONObject(org.json.JSONObject) Animation(com.zhan_dui.model.Animation) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler)

Example 13 with JSONArray

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

the class GitHubParser method fetchReleases.

private void fetchReleases() throws IOException, JSONException {
    JSONArray releases;
    JSONObject release;
    boolean found;
    releases = new JSONArray(new String(RemoteReader.fetch(String.format(RELEASES_URL, username, project))));
    mReleases = new JSONArray();
    found = false;
    for (int i = 0; i < releases.length(); i++) {
        release = releases.getJSONObject(i);
        if (release.getBoolean("draft") || release.getBoolean("prerelease"))
            continue;
        if (mTagFilter != null) {
            String tag = release.getString("tag_name");
            if (!tag.matches(mTagFilter))
                continue;
        }
        if (!found) {
            mLastRelease = release;
            found = true;
        }
        mReleases.put(release);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 14 with JSONArray

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

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

JSONArray (org.json.JSONArray)1596 JSONObject (org.json.JSONObject)1121 JSONException (org.json.JSONException)690 ArrayList (java.util.ArrayList)303 IOException (java.io.IOException)232 Test (org.junit.Test)199 HashMap (java.util.HashMap)105 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)96 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 List (java.util.List)59 HashSet (java.util.HashSet)53 File (java.io.File)49 Query (org.b3log.latke.repository.Query)47 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 Date (java.util.Date)44 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)43 Map (java.util.Map)40 FileNotFoundException (java.io.FileNotFoundException)37 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)36 VolleyError (com.android.volley.VolleyError)35