Example usage for org.json JSONObject getJSONObject

List of usage examples for org.json JSONObject getJSONObject

Introduction

In this page you can find the example usage for org.json JSONObject getJSONObject.

Prototype

public JSONObject getJSONObject(String key) throws JSONException 

Source Link

Document

Get the JSONObject value associated with a key.

Usage

From source file:org.eclipse.orion.server.tests.servlets.git.GitBlameTest.java

@Test
public void testBlameNoCommits() throws IOException, SAXException, JSONException, CoreException {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        //clone a repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        //get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());

        // get blameUri
        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitBlameUri = gitSection.getString(GitConstants.KEY_BLAME);

        // blame request
        request = getGetGitBlameRequest(gitBlameUri);
        response = webConversation.getResource(request);
        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());

        // test//from   www .  j  ava  2  s  .  c o m
        JSONObject blameObject = new JSONObject(response.getText());

        assertEquals(blameObject.length(), 4);
        assertEquals(blameObject.get("Severity"), "Error");
        assertEquals(blameObject.get("HttpCode"), 400);
        assertEquals(blameObject.get("Code"), 0);
    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBlameTest.java

@Test
public void testBlameOneCommit() throws IOException, SAXException, JSONException, CoreException {

    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        //clone a repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        //get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());
        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        //create and modify file
        JSONObject testTxt = getChild(folder, "test.txt");
        modifyFile(testTxt, "line one \n line two \n line 3 \n line 4");

        //commit/*from ww w . j  a v a 2 s  .  c o  m*/
        addFile(testTxt);
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get blame Uri
        JSONObject testTxtGitSection = testTxt.getJSONObject(GitConstants.KEY_GIT);
        String blameUri = testTxtGitSection.getString(GitConstants.KEY_BLAME);

        // blame request
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        // get BlameInfo
        JSONObject blameObject = new JSONObject(response.getText());

        //Test
        assertEquals(blameObject.getString(ProtocolConstants.KEY_TYPE), "Blame");

        JSONArray blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        JSONArray children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        JSONObject child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 4);

    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBlameTest.java

@Test
public void testBlameMultiCommit() throws IOException, SAXException, JSONException, CoreException {

    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        //clone a repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        //get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());
        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        //create file test.txtx
        JSONObject testTxt = getChild(folder, "test.txt");
        modifyFile(testTxt, "line one \n line two \n line 3 \n line 4");

        //commit the file
        addFile(testTxt);/*w  ww. java2  s  .  co m*/
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get the blame uri for this file
        JSONObject testTxtGitSection = testTxt.getJSONObject(GitConstants.KEY_GIT);
        String blameUri = testTxtGitSection.getString(GitConstants.KEY_BLAME);

        // blame the file
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        // testing
        JSONObject blameObject = new JSONObject(response.getText());

        // non blame info tests
        JSONArray blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        JSONArray children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        JSONObject child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 4);

        //save commit info to test
        String commitLocation1 = blameObject.getString(GitConstants.KEY_COMMIT);
        int commitTime1 = blameObject.getInt(GitConstants.KEY_COMMIT_TIME);
        String commitId1 = blameObject.getString(ProtocolConstants.KEY_NAME);

        // modify the file
        modifyFile(testTxt, "LINE ONE \n LINE TWO \n LINE THREE \n LINE FOUR \n LINE FIVE");
        addFile(testTxt);

        //commit the new changes
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get blame uri
        testTxtGitSection = testTxt.getJSONObject(GitConstants.KEY_GIT);
        blameUri = testTxtGitSection.getString(GitConstants.KEY_BLAME);

        // blame file
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        // test
        blameObject = new JSONObject(response.getText());

        // non blame info tests
        assertEquals(blameObject.length(), 4);
        assertEquals(blameObject.getString(ProtocolConstants.KEY_TYPE), "Blame");
        assertEquals(blameObject.getString(ProtocolConstants.KEY_LOCATION), blameUri);

        blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));

        // test first commit
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);

        //test second commit
        blameObject = blame.getJSONObject(0);

        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 5);

        String commitLocation2 = blameObject.getString(GitConstants.KEY_COMMIT);
        int commitTime2 = blameObject.getInt(GitConstants.KEY_COMMIT_TIME);
        String commitId2 = blameObject.getString(ProtocolConstants.KEY_NAME);

        // test that there are not duplicates of the same commit
        assertNotSame(commitId1, commitId2);
        assertNotSame(commitLocation1, commitLocation2);
        assertNotSame(commitTime1, commitTime2);

    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBlameTest.java

@Test
public void testBlameMultiFile() throws IOException, SAXException, JSONException, CoreException {

    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);
    for (IPath clonePath : clonePaths) {
        //clone a repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        //get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());

        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        /*/*from   w  w  w  .ja v a 2 s .c om*/
         * Commit 1
         */
        // create the original file and modify it
        JSONObject testTxt = getChild(folder, "test.txt");
        modifyFile(testTxt, "line one \n line two \n line 3 \n line 4");

        //commit file
        addFile(testTxt);
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get blameURI
        JSONObject testTxtGitSection = testTxt.getJSONObject(GitConstants.KEY_GIT);
        String blameUri = testTxtGitSection.getString(GitConstants.KEY_BLAME);

        // make blame request
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        // test
        JSONObject blameObject = new JSONObject(response.getText());
        assertEquals(blameObject.getString(ProtocolConstants.KEY_TYPE), "Blame");
        assertEquals(blameObject.getString(ProtocolConstants.KEY_LOCATION), blameUri);

        //test blameInfo
        JSONArray blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        JSONArray children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        JSONObject child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 4);

        /*
         * commit 2 - different file
         */

        // create a second file in a different folder
        JSONObject newfolder = getChild(folder, "folder");
        JSONObject folderTxt = getChild(newfolder, "folder.txt");
        modifyFile(folderTxt, "commit me");

        // commit the new file
        addFile(folderTxt);
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit on testFile2.txt", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // make blame request
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        /*
         * These tests should produce the same results as the above tests
         * They should be not affected by the recent commit
         */
        blameObject = new JSONObject(response.getText());
        assertEquals(blameObject.getString(ProtocolConstants.KEY_TYPE), "Blame");
        assertEquals(blameObject.getString(ProtocolConstants.KEY_LOCATION), blameUri);

        //test blameInfo
        blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 4);

        /*
         * commit 3 - original file
         */

        // modify original file
        modifyFile(testTxt, "LINE ONE \n LINE TWO \n LINE THREE \n LINE FOUR \n LINE FIVE");

        //commit the changes
        addFile(testTxt);
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "modified testFile.txt", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        blameUri = testTxtGitSection.getString(GitConstants.KEY_BLAME);

        // do blame computation
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        blameObject = new JSONObject(response.getText());
        assertEquals(blameObject.getString(ProtocolConstants.KEY_TYPE), "Blame");
        assertEquals(blameObject.getString(ProtocolConstants.KEY_LOCATION), blameUri);

        // test
        blame = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        assertNotNull(blameObject.get(ProtocolConstants.KEY_CHILDREN));
        assertEquals(blame.length(), 1);
        blameObject = blame.getJSONObject(0);
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_AUTHOR_IMAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_EMAIL));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMITTER_NAME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_MESSAGE));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT_TIME));
        assertNotNull(blameObject.get(GitConstants.KEY_COMMIT));
        assertNotNull(blameObject.get(ProtocolConstants.KEY_NAME));
        children = blameObject.getJSONArray(ProtocolConstants.KEY_CHILDREN);
        child = children.getJSONObject(0);
        assertEquals(children.length(), 1);
        assertEquals(child.get(GitConstants.KEY_START_RANGE), 1);
        assertEquals(child.get(GitConstants.KEY_END_RANGE), 5);

    }
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitBlameTest.java

@Test
public void testFolderBlame() throws IOException, SAXException, JSONException, CoreException {

    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        //clone a repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        //get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());
        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);

        JSONObject newfolder = getChild(folder, "folder");

        //modifyFile(newfolder, "commit me");

        // commit the new file
        addFile(newfolder);/*w  ww  . j  a  v  a  2 s  . com*/
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "initial commit on testFile2.txt", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        JSONObject newfolderGitSection = newfolder.getJSONObject(GitConstants.KEY_GIT);
        String blameUri = newfolderGitSection.getString(GitConstants.KEY_BLAME);

        // blame request
        request = getGetGitBlameRequest(blameUri);
        response = webConversation.getResource(request);

        // get BlameInfo
        JSONObject blameObject = new JSONObject(response.getText());

        //Test

        assertEquals(blameObject.length(), 4);

        assertEquals(blameObject.get("Severity"), "Error");
        assertEquals(blameObject.get("HttpCode"), 400);
        assertEquals(blameObject.get("Code"), 0);

    }
}

From source file:org.marietjedroid.connect.MarietjeClientChannel.java

public void handleMessage(String token, JSONObject data) throws JSONException {

    System.out.println("processing" + data.toString());
    if (data.getString("type").equals("media_part")) {
        synchronized (tracksRetrieved) {
            JSONObject ding = data.getJSONObject("part");

            @SuppressWarnings("unchecked")
            Iterator<String> it = ding.keys();
            while (it.hasNext())
                tempPartialMedia.add(ding.getJSONArray((it.next().toString())));
            if (this.partialMediaSize == tempPartialMedia.size()) {
                this.partialMedia = tempPartialMedia.toArray(new JSONArray[0]);
                this.tempPartialMedia.clear();
                this.partialMediaSize = -1;
                tracksRetrieved.release();
            }//from   w w w .  j a v  a2 s.co m

        }
    } else if (data.getString("type").equals("media")) {
        synchronized (tracksRetrieved) {
            this.partialMediaSize = data.getInt("count");
            if (this.partialMediaSize == tempPartialMedia.size()) {
                this.partialMedia = tempPartialMedia.toArray(new JSONArray[0]);
                this.tempPartialMedia.clear();
                this.partialMediaSize = 0;
                tracksRetrieved.release();
            }
        }
    } else if (data.getString("type").equals("welcome"))
        return;
    else if (data.getString("type").equals("playing")) {
        this.nowPlaying = data.getJSONObject("playing");
        playingRetrieved.release();
    } else if (data.getString("type").equals("requests")) {
        this.requests = data.getJSONArray("requests");
        this.requestsRetrieved.release();

    } else if (data.getString("type").equals("error_login")) {
        synchronized (loginAttempt) {
            this.loginError = new MarietjeException(data.getString("message"));
            this.loginAttempt.release();
        }
    } else if (data.getString("type").equals("login_token")) {
        synchronized (this.loginToken) {
            this.loginToken = data.getString("login_token");
            this.loginAttempt.release();
        }
    } else if (data.getString("type").equals("logged_in")) {
        synchronized (loginAttempt) {
            this.accessKey = data.getString("accessKey");
            loginAttempt.release();
        }
    } else if (data.getString("type").equals("error_request")) {
        this.requestError = data.getString("message");
        this.requestsRetrieved.release();
    } else if (data.getString("type").equals("query_media_results")) {
        if (data.getInt("token") != server.queryToken) {
            return; // wrong result set
        }
        synchronized (this.queryResults) {
            this.queryResults.clear();
            JSONArray results = data.getJSONArray("results");
            for (int i = 0; results.opt(i) != null; i++) {
                JSONObject m = results.getJSONObject(i);
                this.queryResults.add(new MarietjeTrack(m));
            }
            this.queryResultsRetrieved.release();
        }

    }

    this.setChanged();
    this.notifyObservers(data.getString("type"));
}

From source file:net.freifunk.android.discover.model.Community.java

public void populate(final RequestQueue rq, final CommunityReady communityReady) {

    rq.add(new JsonObjectRequest(getDetailUrl(), null, new Response.Listener<JSONObject>() {
        @Override// www  .j a v  a2  s .  co  m
        public void onResponse(JSONObject jsonObject) {
            try {
                setApiName(jsonObject.getString("name"));
                setApi(jsonObject.getString("api"));
                if (jsonObject.has("metacommunity"))
                    setMetacommunity(jsonObject.getString("metacommunity"));

                JSONObject location = jsonObject.getJSONObject("location");
                setAddressCity(location.getString("city"));
                if (location.has("address")) {
                    JSONObject address = jsonObject.getJSONObject("address");
                    if (address.has("Name"))
                        setAddressName(address.getString("Name"));

                    if (address.has("Street"))
                        setAddressStreet(address.getString("Street"));

                    if (address.has("Zipcode"))
                        setAddressZipcode(address.getString("Zipcode"));
                }
                setLat(location.getDouble("lat"));
                setLon(location.getDouble("lon"));
                setUrl(jsonObject.getString("url"));
                Log.d(TAG, getCommunity().toString());
                communityReady.ready(getCommunity());
            } catch (JSONException e) {
                Log.e(TAG, e.toString());
            }

        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Log.e(TAG, volleyError.toString());
        }
    }));
}

From source file:app.hanks.com.conquer.activity.LoginActivity.java

/**
 * ??// w  w w.  j  a  v  a 2  s . co m
 */
public void getWeiboInfo(final JSONObject obj) {
    // ?http://open.weibo.com/wiki/2/users/show??API
    new Thread() {
        @Override
        public void run() {
            try {
                Map<String, String> params = new HashMap<String, String>();
                if (obj != null) {
                    params.put("access_token", obj.getJSONObject("weibo").getString("access_token"));// ???access_token
                    params.put("uid", obj.getJSONObject("weibo").getString("uid"));// ???uid
                }
                String result = NetUtils.getRequest("https://api.weibo.com/2/users/show.json", params);
                L.i("??" + result);
                JSONObject json = new JSONObject(result);
                nickName = json.getString("screen_name");
                gender = json.getString("gender");
                photoUrl = json.getString("avatar_large").replace("\\", "");
                city = json.getString("location");
                goDialogActivity();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }.start();
}

From source file:app.hanks.com.conquer.activity.LoginActivity.java

/**
 * ?QQ?//from  w w  w.ja  va  2  s. c om
 */
public void getQQInfo(final JSONObject obj) {
    // ?APPID??????
    // ?http://wiki.connect.qq.com/get_user_info??API??QQ????
    new Thread() {
        @Override
        public void run() {
            try {
                Map<String, String> params = new HashMap<String, String>();
                // ?json
                // {
                // "qq": {
                // "openid": "B4F5ABAD717CCC93ABF3BF28D4BCB03A",
                // "access_token": "05636ED97BAB7F173CB237BA143AF7C9",
                // "expires_in": 7776000
                // }
                // }
                if (obj != null) {
                    // params.put("access_token", obj.getJSONObject("qq")
                    // .getString("access_token"));//
                    // ???access_token
                    // params.put("uid",
                    // obj.getJSONObject("weibo").getString("uid"));//
                    // ???uid
                    params.put("access_token", obj.getJSONObject("qq").getString("access_token"));// QQ??access_token
                    params.put("openid", obj.getJSONObject("qq").getString("openid"));
                    params.put("oauth_consumer_key", Constants.QQ_KEY);// oauth_consumer_keyQQ???appid
                    params.put("format", "json");// ?--?
                }
                String result = NetUtils.getRequest("https://graph.qq.com/user/get_user_info", params);
                L.i("login", "QQ?" + result);
                JSONObject json = new JSONObject(result);
                nickName = json.getString("nickname");
                gender = json.getString("gender");
                photoUrl = json.getString("figureurl_qq_2").replace("\\", "");
                city = json.getString("province") + " " + json.getString("city");
                goDialogActivity();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }.start();
}

From source file:com.whizzosoftware.hobson.dto.property.PropertyContainerDTO.java

private PropertyContainerDTO(JSONObject json) {
    if (json.has(JSONAttributes.CCLASS)) {
        containerClass = new PropertyContainerClassDTO.Builder(json.getJSONObject(JSONAttributes.CCLASS))
                .build();//from w  ww  . j a  v a  2  s . c  o m
    }
    if (json.has(JSONAttributes.VALUES)) {
        values = new HashMap<>();
        JSONObject jp = json.getJSONObject(JSONAttributes.VALUES);
        for (Object o : jp.keySet()) {
            String key = o.toString();
            Object v = jp.get(key);
            if (JSONObject.NULL.equals(v)) {
                values.put(key, null);
            } else if (v instanceof Serializable || v instanceof JSONArray || v instanceof JSONObject) {
                values.put(key, v);
            } else {
                throw new HobsonRuntimeException("Invalid property value for " + key + ": " + v);
            }
        }
    }
}