Example usage for org.json JSONObject getJSONArray

List of usage examples for org.json JSONObject getJSONArray

Introduction

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

Prototype

public JSONArray getJSONArray(String key) throws JSONException 

Source Link

Document

Get the JSONArray value associated with a key.

Usage

From source file:com.roiland.crm.sm.core.service.impl.ContacterAPIImpl.java

@SuppressWarnings("unchecked")
@Override//from w w  w.j  a  v a  2 s . c o  m
public List<Contacter> getContacterList(String userID, String dealerOrgID, String projectID, String customerID)
        throws ResponseException {
    ReleasableList<Contacter> contacterList = null;
    try {

        // ??.
        if (userID == null || dealerOrgID == null) {
            throw new ResponseException("userID or dealerOrgID is null.");
        }

        JSONObject params = new JSONObject();
        params.put("userID", userID);
        params.put("dealerOrgID", dealerOrgID);
        params.put("projectID", projectID);
        params.put("customerID", customerID);

        // ?Key
        String key = getKey(URLContact.METHOD_GET_CONTACTER_LIST, params);

        // ????
        contacterList = lruCache.get(key);
        if (contacterList != null && !contacterList.isExpired()) {
            return contacterList;
        }

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_CONTACTER_LIST), params, null);
        if (response.isSuccess()) {
            contacterList = new ArrayReleasableList<Contacter>();
            String data = getSimpleString(response);
            Log.i("getContacterList", data);
            JSONObject jsonBean = new JSONObject(data);
            JSONArray contacter = jsonBean.getJSONArray("result");
            int n = contacter.length();
            for (int i = 0; i < n; i++) {
                JSONObject json = contacter.getJSONObject(i);
                Contacter resultContacter = new Contacter();
                resultContacter.setContacterID(json.getString("contacterID"));
                resultContacter.setProjectID(String.valueOf(json.getString("projectID")));
                resultContacter.setCustomerID(String.valueOf(json.getString("customerID")));
                resultContacter.setContName(parsingString(json.get("contName")));
                resultContacter.setContMobile(parsingString(json.get("contMobile")));
                resultContacter.setContOtherPhone(parsingString(json.get("contOtherPhone")));
                resultContacter.setIsPrimContanter(String.valueOf(json.getBoolean("isPrimContanter")));
                resultContacter.setContGenderCode(parsingString(json.get("contGenderCode")));
                resultContacter.setContGender(parsingString(json.get("contGender")));
                resultContacter
                        .setContBirthday(String.valueOf(DataVerify.isZero(json.getString("contBirthday"))));
                resultContacter.setIdNumber(parsingString(json.get("idNumber")));
                resultContacter.setAgeScopeCode(parsingString(json.get("ageScopeCode")));
                resultContacter.setAgeScope(parsingString(json.get("ageScope")));
                resultContacter.setContType(parsingString(json.get("contType")));
                resultContacter.setContTypeCode(String.valueOf(json.getString("contTypeCode")));
                resultContacter.setContRelationCode(String.valueOf(json.getString("contRelationCode")));
                resultContacter.setContRelation(parsingString(json.get("contRelation")));
                resultContacter
                        .setLicenseValid(StringUtils.toLong(DataVerify.isZero(json.getString("licenseValid"))));
                contacterList.add(resultContacter);

            }
            // ?
            if (contacterList != null) {
                lruCache.put(key, contacterList);
            }
            return contacterList;
        }
        throw new ResponseException();
    } catch (IOException e) {
        Log.e(tag, "Connection network error.", e);
        throw new ResponseException(e);
    } catch (JSONException e) {
        Log.e(tag, "Parsing data error.", e);
        throw new ResponseException(e);
    }

}

From source file:com.roiland.crm.sm.core.service.impl.ContacterAPIImpl.java

@Override
public List<Dictionary> getEmployeeList() throws ResponseException {
    List<Dictionary> employeeList = null;
    try {//from  w w  w. j av a  2  s  .  c  om
        JSONObject params = new JSONObject();
        params.put("status", "3");
        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_EMPLOYEE_LIST), params, null);
        if (response.isSuccess()) {
            employeeList = new ArrayList<Dictionary>();
            JSONObject result = new JSONObject(getSimpleString(response));
            JSONArray array = result.getJSONArray("list");
            for (int i = 0; i < array.length(); i++) {
                Dictionary dic = new Dictionary();
                JSONObject object = array.getJSONObject(i);
                dic.setDicKey(object.getString("id"));
                dic.setDicValue(object.getString("name"));
                employeeList.add(dic);
            }
        }
    } catch (IOException e) {
        Log.e(tag, "Parsing data error.", e);
        throw new ResponseException(e);
    } catch (JSONException e) {
        Log.e(tag, "Parsing data error.", e);
        throw new ResponseException(e);
    }

    return employeeList;
}

From source file:org.melato.bus.otp.OTPParser.java

static Itinerary parseItinerary(JSONObject json) throws JSONException {
    JSONArray legs = json.getJSONArray("legs");
    Itinerary itinerary = new Itinerary();
    itinerary.legs = new Leg[legs.length()];
    itinerary.startTime = new Date(json.getLong("startTime"));
    itinerary.endTime = new Date(json.getLong("endTime"));
    for (int i = 0; i < itinerary.legs.length; i++) {
        itinerary.legs[i] = parseLeg(legs.getJSONObject(i));
    }/*from   w  w  w  . j  ava  2  s.  co  m*/
    return itinerary;
}

From source file:org.melato.bus.otp.OTPParser.java

public static Plan parse(String data) {
    try {//from ww  w  .j  a  v a2  s  .  c  om
        Plan plan = new Plan();
        plan.itineraries = new Itinerary[0];
        JSONObject json = new JSONObject(data);
        JSONObject jsonPlan = getObject(json, "plan");
        if (jsonPlan != null) {
            JSONArray jsonItineraries = jsonPlan.getJSONArray("itineraries");
            if (jsonItineraries != null) {
                Itinerary[] itineraries = new Itinerary[jsonItineraries.length()];
                for (int i = 0; i < itineraries.length; i++) {
                    itineraries[i] = parseItinerary(jsonItineraries.getJSONObject(i));
                }
                plan.itineraries = itineraries;
            }
        }
        plan.error = parseError(json);
        return plan;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.trellmor.berrytube.Poll.java

/**
 * Constructs a <code>Poll</code> from a <code>JSONObject<code>
 * /*from ww  w.j  a  v  a2  s .com*/
 * @param poll <code>JSONObject<code> containing the poll data
 * @throws JSONException
 */
public Poll(JSONObject poll) throws JSONException {
    mTitle = poll.getString("title");
    mCreator = poll.getString("title");
    mObscure = poll.getBoolean("obscure");

    JSONArray options = poll.getJSONArray("options");
    for (int i = 0; i < options.length(); i++) {
        mOptions.add(options.getString(i));
    }

    JSONArray votes = poll.getJSONArray("votes");
    for (int i = 0; i < votes.length(); i++) {
        mVotes.add(votes.optInt(i, -1));
    }
}

From source file:br.unicamp.cst.behavior.bn.Behavior.java

/**
 *  Checks if there is a current behavior proposition in working storage that is using the resources this behavior needs
 * @return if there is conflict of resources
 *///  w w w.j  a  va  2s .  c  om
private boolean resourceConflict() {//TODO must develop this idea further
    boolean resourceConflict = false;
    ArrayList<MemoryObject> allOfType = new ArrayList<MemoryObject>();

    if (ws != null)
        allOfType.addAll(ws.getAllOfType("BEHAVIOR_PROPOSITION"));

    ArrayList<String> usedResources = new ArrayList<String>();

    if (allOfType != null) {

        for (MemoryObject bp : allOfType) {
            try {
                JSONObject jsonBp = new JSONObject(bp.getI());
                //System.out.println("=======> bp.getInfo(): "+bp.getInfo());
                boolean performed = jsonBp.getBoolean("PERFORMED");
                if (!performed) {//otherwise it is not consuming those resources

                    JSONArray resourceList = jsonBp.getJSONArray("RESOURCELIST");

                    for (int i = 0; i < resourceList.length(); i++) {
                        usedResources.add(resourceList.getString(i));
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
    //      System.out.println("%%% usedResources: "+usedResources);
    //      System.out.println("%%% getResourceList: "+getResourceList());
    int sizeBefore = usedResources.size();
    usedResources.removeAll(this.getResourceList());
    int sizeLater = usedResources.size();

    if (sizeLater != sizeBefore) {
        resourceConflict = true;
        //         System.out.println("%%%%%%%%%%%%%%%%%%%%% There was a conflict here");
    }

    return resourceConflict;
}

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  w w w  .  ja  v a2  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);/*from www .  j  av  a2s . c  o 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);

        /*// www  .  j a va 2s.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:com.norman0406.slimgress.API.Knobs.Knobs.java

protected static List<Integer> getIntArray(JSONObject json, String key) throws JSONException {
    JSONArray jsonArray = json.getJSONArray(key);
    List<Integer> ret = new ArrayList<Integer>();
    for (int i = 0; i < jsonArray.length(); i++) {
        Object obj = jsonArray.get(i);
        if (obj instanceof Integer)
            ret.add((Integer) obj);
    }/*from   www .  j  av  a  2s  . com*/
    return ret;
}