Example usage for org.json JSONObject get

List of usage examples for org.json JSONObject get

Introduction

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

Prototype

public Object get(String key) throws JSONException 

Source Link

Document

Get the value object associated with a key.

Usage

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

@Test
public void testDiffFromLog() throws Exception {
    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);

        // modify
        JSONObject testTxt = getChild(folder, "test.txt");
        modifyFile(testTxt, "hello");
        addFile(testTxt);//from  w  w  w .  ja  va2 s .c o m

        // commit
        request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "2nd commit", false);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // get the full log
        JSONArray commits = log(gitHeadUri);
        assertEquals(2, commits.length());
        JSONObject commit = commits.getJSONObject(0);
        assertEquals("2nd commit", commit.get(GitConstants.KEY_COMMIT_MESSAGE));
        JSONArray diffs = commit.getJSONArray(GitConstants.KEY_COMMIT_DIFFS);
        assertEquals(1, diffs.length());

        // check diff object
        JSONObject diff = diffs.getJSONObject(0);
        assertEquals("test.txt", diff.getString(GitConstants.KEY_COMMIT_DIFF_NEWPATH));
        assertEquals("test.txt", diff.getString(GitConstants.KEY_COMMIT_DIFF_OLDPATH));
        assertEquals(Diff.TYPE, diff.getString(ProtocolConstants.KEY_TYPE));
        assertEquals(ChangeType.MODIFY,
                ChangeType.valueOf(diff.getString(GitConstants.KEY_COMMIT_DIFF_CHANGETYPE)));
        String contentLocation = diff.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
        String fileContent = getFileContent(
                new JSONObject().put(ProtocolConstants.KEY_LOCATION, contentLocation));
        assertEquals("hello", fileContent);
        String diffLocation = diff.getString(GitConstants.KEY_DIFF);

        // check diff location
        String[] parts = GitDiffTest.getDiff(diffLocation);

        StringBuilder sb = new StringBuilder();
        sb.append("diff --git a/test.txt b/test.txt").append("\n");
        sb.append("index 30d74d2..b6fc4c6 100644").append("\n");
        sb.append("--- a/test.txt").append("\n");
        sb.append("+++ b/test.txt").append("\n");
        sb.append("@@ -1 +1 @@").append("\n");
        sb.append("-test").append("\n");
        sb.append("\\ No newline at end of file").append("\n");
        sb.append("+hello").append("\n");
        sb.append("\\ No newline at end of file").append("\n");
        assertEquals(sb.toString(), parts[1]);
    }
}

From source file:com.EconnectTMS.CustomerInformation.java

public void Run(String IncomingMessage, String intid)
        throws MalformedURLException, UnsupportedEncodingException, IOException {

    try {//w  w  w  . j a v a  2  s  . c  o m
        strRecievedData = IncomingMessage.split("#");
        processingcode = strRecievedData[0];
        switch (processingcode) {
        case "800000":
            AccountNumber = strRecievedData[1];
            URL url = new URL(CUSTOMER_DETAILS_URL);
            Map<String, String> params = new LinkedHashMap<>();

            params.put("username", CUSTOMER_DETAILS_USERNAME);
            params.put("password", CUSTOMER_DETAILS_PASSWORD);
            params.put("source", CUSTOMER_DETAILS_SOURCE_ID);
            params.put("account", AccountNumber);

            postData = new StringBuilder();
            for (Map.Entry<String, String> param : params.entrySet()) {
                if (postData.length() != 0) {
                    postData.append('&');
                }
                postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
                postData.append('=');
                postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
            }
            urlParameters = postData.toString();
            conn = url.openConnection();
            conn.setDoOutput(true);

            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(urlParameters);
            writer.flush();

            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            while ((line = reader.readLine()) != null) {
                result += line;
            }
            writer.close();
            reader.close();

            JSONObject respobj = new JSONObject(result);
            if (respobj.has("FSTNAME") || respobj.has("MIDNAME") || respobj.has("LSTNAME")) {
                if (respobj.has("FSTNAME")) {
                    fname = respobj.get("FSTNAME").toString().toUpperCase() + ' ';
                }
                if (respobj.has("MIDNAME")) {
                    mname = respobj.get("MIDNAME").toString().toUpperCase() + ' ';
                }
                if (respobj.has("LSTNAME")) {
                    lname = respobj.get("LSTNAME").toString().toUpperCase() + ' ';
                }
                strCustomerName = fname + mname + lname;
            } else {
                strCustomerName = " ";
            }
            System.out.println("result:" + result);
            func.SendPOSResponse(strCustomerName + "#", intid);
            return;
        default:
            break;
        }
    } catch (Exception ex) {
        strCustomerName = "";
        func.log("\nSEVERE CustomerInformation() :: " + ex.getMessage() + "\n" + func.StackTraceWriter(ex),
                "ERROR");
    }
}

From source file:com.microsoft.mimickeralarm.utilities.Loggable.java

public void putJSON(JSONObject json) {
    try {//from ww w .  j a  va 2 s  .com
        Iterator<?> keys = json.keys();

        while (keys.hasNext()) {
            String key = (String) keys.next();
            Properties.put(key, json.get(key));
        }
    } catch (JSONException ex) {
        Logger.trackException(ex);
    }
}

From source file:org.b3log.solo.util.comparator.ArticleUpdateDateComparator.java

@Override
public int compare(final JSONObject article1, final JSONObject article2) {
    try {/*ww w.  ja  v a  2 s .c  om*/
        final Date date1 = (Date) article1.get(Article.ARTICLE_UPDATE_DATE);
        final Date date2 = (Date) article2.get(Article.ARTICLE_UPDATE_DATE);

        return date2.compareTo(date1);
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.wso2.appmanager.integration.test.cases.StoreLogoutTestCase.java

@Test(description = TEST_DESCRIPTION)
public void StoreLogoutTestCase() throws Exception {
    HttpResponse storeLogoutResponse = appmStoreRestClient.logout();
    int responseCode = storeLogoutResponse.getResponseCode();
    JSONObject payload = new JSONObject(storeLogoutResponse.getData());
    assertTrue(responseCode == 200, responseCode + " status code received.");
    assertTrue(!(Boolean) payload.get("error"), "Error when try to logout form store.");
}

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

/**
 * @see com.roiland.crm.core.service.ProjectAPI#getProjectInfo(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 *//*from  w  ww  .  j  ava2  s.  c om*/
@Override
public Project getProjectInfo(String userID, String dealerOrgID, String projectID, String customerID)
        throws ResponseException {
    Project project = 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);

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_PROJECT_INFO), params, null);
        if (response.isSuccess()) {
            project = new Project();
            JSONObject result = new JSONObject(getSimpleString(response)).getJSONObject("result");
            JSONObject customerEntityresult = result.getJSONObject("customerEntity");
            JSONObject purchaseCarIntentionresult = result.getJSONObject("purchaseCarIntention");

            Customer customerEntity = new Customer();
            PurchaseCarIntention purchaseCarIntention = new PurchaseCarIntention();
            if (StringUtils.isEmpty(projectID)) {
                customerEntity.setProjectID(projectID);
            }
            customerEntity.setCustomerID(parsingString(customerEntityresult.get("customerID")));
            customerEntity.setCustName(parsingString(customerEntityresult.get("custName")));
            customerEntity.setCustFromCode(parsingString(customerEntityresult.get("custFromCode")));
            customerEntity.setCustFrom(parsingString(customerEntityresult.get("custFrom")));
            customerEntity.setCustTypeCode(parsingString(customerEntityresult.get("custTypeCode")));
            customerEntity.setCustType(parsingString(customerEntityresult.get("custType")));
            customerEntity.setInfoFromCode(parsingString(customerEntityresult.get("infoFromCode")));
            customerEntity.setInfoFrom(parsingString(customerEntityresult.get("infoFrom")));
            customerEntity.setCollectFromCode(parsingString(customerEntityresult.get("collectFromCode")));
            customerEntity.setCollectFrom(parsingString(customerEntityresult.get("collectFrom")));
            customerEntity.setCustMobile(parsingString(customerEntityresult.get("custMobile")));
            customerEntity.setCustOtherPhone(parsingString(customerEntityresult.get("custOtherPhone")));
            customerEntity.setGenderCode(parsingString(customerEntityresult.get("genderCode")));
            customerEntity.setGender(parsingString(customerEntityresult.get("gender")));
            customerEntity.setBirthday(parsingString(customerEntityresult.get("birthday")));
            customerEntity.setIdTypeCode((parsingString(customerEntityresult.get("idTypeCode"))));
            customerEntity.setIdType(parsingString(customerEntityresult.get("idType")));
            customerEntity.setIdNumber(parsingString(customerEntityresult.get("idNumber")));
            customerEntity.setProvinceCode(parsingString(customerEntityresult.get("provinceCode")));
            customerEntity.setProvince(parsingString(customerEntityresult.get("province")));
            customerEntity.setCityCode(parsingString(customerEntityresult.get("cityCode")));
            customerEntity.setCity(parsingString(customerEntityresult.get("city")));
            customerEntity.setDistrictCode(parsingString(customerEntityresult.get("districtCode")));
            customerEntity.setDistrict(parsingString(customerEntityresult.get("district")));
            customerEntity.setQq(parsingString(customerEntityresult.get("qq")));
            customerEntity.setAddress(parsingString(customerEntityresult.get("address")));
            customerEntity.setPostcode(parsingString(customerEntityresult.get("postcode")));
            customerEntity.setEmail(parsingString(customerEntityresult.get("email")));
            customerEntity.setConvContactTime(parsingString(customerEntityresult.get("convContactTime")));
            //              customerEntity.setConvContactTimeCode((customerEntityresult
            //                              .get("convContactTimeCode")));
            customerEntity
                    .setExpectContactWayCode(parsingString(customerEntityresult.get("expectContactWayCode")));
            customerEntity.setExpectContactWay((parsingString(customerEntityresult.get("expectContactWay"))));
            customerEntity.setFax(parsingString(customerEntityresult.get("fax")));
            //              customerEntity.setExistingCarCode(String
            //                      .valueOf(parsingString(customerEntityresult
            //                              .get("existingCarCode"))));
            customerEntity.setExistingCarBrand(parsingString(customerEntityresult.get("existingCarBrand")));
            customerEntity.setIndustryCode(parsingString(customerEntityresult.get("industryCode")));
            customerEntity.setPositionCode(parsingString(customerEntityresult.get("positionCode")));
            customerEntity.setEducationCode(parsingString(customerEntityresult.get("educationCode")));
            customerEntity.setExistingCar(parsingString(customerEntityresult.get("existingCar")));
            customerEntity.setIndustry(parsingString(customerEntityresult.get("industry")));
            customerEntity.setPosition(parsingString(customerEntityresult.get("position")));
            customerEntity.setEducation(parsingString(customerEntityresult.get("education")));
            customerEntity.setCustInterestCode1(parsingString(customerEntityresult.get("custInterestCode1")));
            customerEntity.setCustInterest1((parsingString(customerEntityresult.get("custInterest1"))));
            customerEntity.setCustInterestCode2((parsingString(customerEntityresult.get("custInterestCode2"))));
            customerEntity.setCustInterest2(parsingString(customerEntityresult.get("custInterest2")));
            customerEntity.setCustInterestCode3(parsingString(customerEntityresult.get("custInterestCode3")));
            customerEntity.setCustInterest3(parsingString(customerEntityresult.get("custInterest3")));
            customerEntity.setExistLisenPlate(parsingString(customerEntityresult.get("existLisenPlate")));
            customerEntity.setEnterpTypeCode(parsingString(customerEntityresult.get("enterpTypeCode")));
            customerEntity.setEnterpType(parsingString(customerEntityresult.get("enterpType")));
            customerEntity
                    .setEnterpPeopleCountCode(parsingString(customerEntityresult.get("enterpPeopleCountCode")));
            customerEntity.setEnterpPeopleCount(parsingString(customerEntityresult.get("enterpPeopleCount")));
            customerEntity
                    .setRegisteredCapitalCode(parsingString(customerEntityresult.get("registeredCapitalCode")));
            customerEntity.setRegisteredCapital(parsingString(customerEntityresult.get("registeredCapital")));
            //              customerEntity.setCompeCarModelCode(String
            //                      .valueOf(parsingString(customerEntityresult
            //                              .get("compeCarModelCode"))));
            customerEntity.setCompeCarModel(parsingString(customerEntityresult.get("compeCarModel")));
            customerEntity.setRebuyStoreCustTag(
                    Boolean.parseBoolean((parsingString(customerEntityresult.get("rebuyStoreCustTag")))));
            customerEntity.setRebuyOnlineCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("rebuyOnlineCustTag"))));
            customerEntity.setChangeCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("changeCustTag"))));
            customerEntity.setLoanCustTag(
                    Boolean.parseBoolean((parsingString(customerEntityresult.get("loanCustTag")))));
            customerEntity.setHeaderQuartCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("headerQuartCustTag"))));
            customerEntity.setRegularCustTag(
                    Boolean.parseBoolean(parsingString(customerEntityresult.get("regularCustTag"))));
            customerEntity.setRegularCustCode(parsingString(customerEntityresult.get("regularCustCode")));
            customerEntity.setRegularCust(parsingString(customerEntityresult.get("regularCust")));
            customerEntity
                    .setBigCustTag(Boolean.parseBoolean(parsingString(customerEntityresult.get("bigCustTag"))));
            customerEntity.setBigCustsCode(parsingString(customerEntityresult.get("bigCustsCode")));
            customerEntity.setBigCusts(parsingString(customerEntityresult.get("bigCusts")));
            customerEntity.setCustComment(parsingString(customerEntityresult.get("custComment")));
            //customerEntity.setHasUnexePlan(parsingString(customerEntityresult.get("hasUnexePlan")));

            purchaseCarIntention.setBrandCode(parsingString(purchaseCarIntentionresult.get("brandCode")));
            purchaseCarIntention.setBrand(parsingString(purchaseCarIntentionresult.get("brand")));

            purchaseCarIntention.setModelCode(parsingString(purchaseCarIntentionresult.get("modelCode")));
            purchaseCarIntention.setModel(parsingString(purchaseCarIntentionresult.get("model")));
            purchaseCarIntention
                    .setOutsideColorCode(parsingString(purchaseCarIntentionresult.get("outsideColorCode")));
            purchaseCarIntention.setOutsideColor(parsingString(purchaseCarIntentionresult.get("outsideColor")));
            purchaseCarIntention
                    .setInsideColorCode(parsingString(purchaseCarIntentionresult.get("insideColorCode")));
            purchaseCarIntention.setInsideColor(parsingString(purchaseCarIntentionresult.get("insideColor")));
            purchaseCarIntention.setInsideColorCheck(
                    purchaseCarIntentionresult.getBoolean("insideColorCheck") ? true : false);
            purchaseCarIntention.setCarConfigurationCode(
                    parsingString(purchaseCarIntentionresult.get("carConfigurationCode")));
            purchaseCarIntention
                    .setCarConfiguration(parsingString(purchaseCarIntentionresult.get("carConfiguration")));
            purchaseCarIntention.setSalesQuote(parsingString(purchaseCarIntentionresult.get("salesQuote")));
            purchaseCarIntention.setDealPriceIntervalCode(
                    parsingString(purchaseCarIntentionresult.get("dealPriceIntervalCode")));
            purchaseCarIntention
                    .setDealPriceInterval(parsingString(purchaseCarIntentionresult.get("dealPriceInterval")));
            purchaseCarIntention.setPaymentCode(parsingString(purchaseCarIntentionresult.get("paymentCode")));
            purchaseCarIntention.setPayment(parsingString(purchaseCarIntentionresult.get("payment")));
            purchaseCarIntention
                    .setPreorderCount(parsingString(purchaseCarIntentionresult.get("preorderCount")));
            purchaseCarIntention.setPreorderDate(purchaseCarIntentionresult.isNull("preorderDate") ? 0L
                    : purchaseCarIntentionresult.getLong("preorderDate"));
            purchaseCarIntention
                    .setFlowStatusCode(parsingString(purchaseCarIntentionresult.get("flowStatusCode")));
            purchaseCarIntention.setFlowStatus(parsingString(purchaseCarIntentionresult.get("flowStatus")));
            purchaseCarIntention.setDealPossibility(purchaseCarIntentionresult.isNull("dealPossibility") ? ""
                    : parsingString(purchaseCarIntentionresult.get("dealPossibility")));
            purchaseCarIntention.setPurchMotivationCode(
                    parsingString(purchaseCarIntentionresult.get("purchMotivationCode")));
            purchaseCarIntention
                    .setPurchMotivation(parsingString(purchaseCarIntentionresult.get("purchMotivation")));
            purchaseCarIntention.setChassisNo(parsingString(purchaseCarIntentionresult.get("chassisNo")));
            purchaseCarIntention.setEngineNo(parsingString(purchaseCarIntentionresult.get("engineNo")));
            purchaseCarIntention.setLicensePlate(parsingString(purchaseCarIntentionresult.get("licensePlate")));
            purchaseCarIntention.setLicenseProp(parsingString(purchaseCarIntentionresult.get("licenseProp")));
            purchaseCarIntention
                    .setLicensePropCode(parsingString(purchaseCarIntentionresult.get("licensePropCode")));
            purchaseCarIntention.setPickupDate(parsingString(purchaseCarIntentionresult.get("pickupDate")));
            purchaseCarIntention.setPreorderTag(parsingString(purchaseCarIntentionresult.get("preorderTag")));
            purchaseCarIntention.setGiveupTag(purchaseCarIntentionresult.getBoolean("giveupTag"));
            purchaseCarIntention.setGiveupReason(parsingString(purchaseCarIntentionresult.get("giveupReason")));
            //              purchaseCarIntention.setGiveupReasonCode(String
            //                      .valueOf(parsingString(purchaseCarIntentionresult
            //                              .get("giveupReasonCode")));
            purchaseCarIntention.setInvoiceTitle(parsingString(purchaseCarIntentionresult.get("invoiceTitle")));
            purchaseCarIntention
                    .setProjectComment(parsingString(purchaseCarIntentionresult.get("projectComment")));
            // ??
            purchaseCarIntention.setHasActiveOrder(purchaseCarIntentionresult.getBoolean("hasActiveOrder"));
            // ?
            purchaseCarIntention.setHasActiveDrive(purchaseCarIntentionresult.getBoolean("hasActiveDrive"));
            //?
            purchaseCarIntention.setHasUnexePlan(purchaseCarIntentionresult.getBoolean("hasUnexePlan"));
            //???
            purchaseCarIntention.setOrderStatus(parsingString(purchaseCarIntentionresult.get("orderStatus")));
            project.setCustomer(customerEntity);
            project.setPurchaseCarIntention(purchaseCarIntention);

            return project;
        }
        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.ProjectAPIImpl.java

/**
 * @see com.roiland.crm.core.service.ProjectAPI#getCustomerProjectList(java.lang.String, java.lang.String)
 *//*from w w  w  .  j a va 2 s . c o  m*/
@SuppressWarnings("unchecked")
@Override
public List<Project> getCustomerProjectList(String userID, String customerID) throws ResponseException {
    // ?
    ReleasableList<Project> projectList = null;
    try {
        if (userID == null) {
            throw new ResponseException("userID is null.");
        }
        JSONObject params = new JSONObject();
        params.put("userID", userID);
        params.put("customerID", customerID);

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

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_CUSTOMER_PROJECT_LIST), params, null);

        if (response.isSuccess()) {
            projectList = new ArrayReleasableList<Project>();
            JSONObject jsonBean = new JSONObject(getSimpleString(response));
            JSONArray project = jsonBean.getJSONArray("result");

            for (int i = 0; i < project.length(); i++) {
                JSONObject json = project.getJSONObject(i);
                Project result = new Project();
                Customer cust = new Customer();
                result.setProjectID("projectID");
                cust.setProjectID(json.getString("projectID"));
                cust.setCustName(json.getString("custName"));
                cust.setCustMobile(json.getString("custMobile"));
                cust.setCustOtherPhone(json.getString("custOtherPhone"));
                cust.setHasUnexePlan(json.getString("hasUnexePlan"));
                cust.setCustomerID(json.getString("customerID"));
                cust.setCustFrom(json.getString("custFrom"));
                cust.setCustFromCode(json.getString("custFromCode"));
                cust.setCustType(json.getString("custType"));
                cust.setCustTypeCode(json.getString("custTypeCode"));
                cust.setCustComment(json.getString("custComment"));
                cust.setIdNumber(json.getString("idNumber"));

                PurchaseCarIntention purchaseCarIntention = new PurchaseCarIntention();
                purchaseCarIntention.setBrandCode(json.getString("brandCode"));
                purchaseCarIntention.setBrand(parsingString(json.get("brand")));
                purchaseCarIntention.setModelCode(json.getString("modelCode"));
                purchaseCarIntention.setModel(parsingString(json.get("model")));
                purchaseCarIntention.setFlowStatus(parsingString(json.get("flowStatus")));
                purchaseCarIntention.setFlowStatusCode("flowStatusCode");
                purchaseCarIntention.setInsideColorCheck(
                        Boolean.parseBoolean(String.valueOf(json.getString("insideColorCheck"))));

                purchaseCarIntention.setPreorderDate(json.getLong("preorderDate"));
                purchaseCarIntention.setProjectComment(json.getString("projectComment"));
                purchaseCarIntention.setOutsideColorCode(json.getString("outsideColorCode"));
                purchaseCarIntention.setOutsideColor(json.getString("outsideColor"));
                purchaseCarIntention.setInsideColor(json.getString("insideColor"));
                purchaseCarIntention.setInsideColorCode(json.getString("insideColorCode"));
                purchaseCarIntention.setCarConfiguration(json.getString("carConfiguration"));
                purchaseCarIntention.setCarConfigurationCode(json.getString("carConfigurationCode"));

                result.setCustomer(cust);
                result.setPurchaseCarIntention(purchaseCarIntention);
                projectList.add(result);
            }

            return projectList;
        }
        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);
    } catch (Exception e) {
        throw new ResponseException(e);
    }
}

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

/** 
 * @see com.roiland.crm.sm.core.service.ProjectAPI#searchSalesOppoFunncelList(long, long)
 *//* w w w.j  a  va2  s . co m*/
@Override
public List<Project> searchSalesOppoFunncelList(long startDate, long endDate, int startNum, int rowCount)
        throws ResponseException {
    ReleasableList<Project> projectList = null;
    try {
        JSONObject params = new JSONObject();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        params.put("startNum", startNum);
        params.put("rowCount", rowCount);

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_SEARCH_PROJECT_FUNNEL), params, null);
        if (response.isSuccess()) {
            projectList = new ArrayReleasableList<Project>();
            JSONObject jsonBean = new JSONObject(getSimpleString(response));

            JSONArray array = jsonBean.getJSONArray("list");
            if (array != null) {
                for (int i = 0; i < array.length(); i++) {
                    JSONObject json = array.getJSONObject(i);
                    Project result = new Project();
                    Customer cust = new Customer();
                    result.setProjectID(json.getString("projectID")); //project IDProject
                    cust.setProjectID(json.getString("projectID"));
                    cust.setCustName(parsingString(json.get("custName"))); //??

                    PurchaseCarIntention purchaseCarIntention = new PurchaseCarIntention();
                    purchaseCarIntention.setBrand(parsingString(json.get("brand"))); //?
                    purchaseCarIntention.setModel(parsingString(json.get("model"))); //
                    purchaseCarIntention.setFlowStatus(parsingString(json.get("flowStatus"))); //??
                    purchaseCarIntention.setPreorderDate(parsingLong(json.getString("provideDate"))); //
                    purchaseCarIntention.setProjectComment(parsingString(json.get("moment"))); //
                    purchaseCarIntention.setOutsideColor(parsingString(json.get("outsideColor"))); //
                    purchaseCarIntention.setInsideColor(parsingString(json.get("insideColor"))); //
                    purchaseCarIntention.setAbandonFlag(parsingString(json.get("abandonFlag"))); //??
                    purchaseCarIntention.setPreorderCount(parsingString(json.get("revenue"))); //?
                    purchaseCarIntention.setDealPossibility(parsingString(json.get("win"))); //??
                    purchaseCarIntention.setDealPriceInterval(parsingString(json.get("expect"))); //
                    purchaseCarIntention.setEmployeeName(parsingString(json.get("saleMan"))); //

                    result.setCustomer(cust);
                    result.setPurchaseCarIntention(purchaseCarIntention);
                    projectList.add(result);
                }
            }
        }

    } catch (IOException e) {
        throw new ResponseException(e);
    } catch (JSONException e) {
        throw new ResponseException(e);
    }
    return projectList;
}

From source file:io.github.grahambell.taco.TacoTransport.java

/**
 * Convert JSON object to Java Map./*from   w  w  w .  j  a  v  a 2 s . c om*/
 *
 * Each entry in the object is converted using the {@link #jsonToObject}
 * method.
 *
 * @param json the JSON object
 * @return Java Map representation of the object
 * @throws TacoException on error in conversion
 */
public Map<String, Object> jsonToMap(JSONObject json) throws TacoException {
    Map map = new HashMap<String, Object>();

    for (Iterator<String> i = json.keys(); i.hasNext();) {
        String key = i.next();
        map.put(key, jsonToObject(json.get(key)));
    }

    return map;
}

From source file:ai.susi.mind.SusiThought.java

public List<String> getObservations(String featureName) {
    List<String> list = new ArrayList<>();
    JSONArray table = this.getData();
    if (table != null && table.length() > 0) {
        for (int rc = 0; rc < table.length(); rc++) {
            JSONObject row = table.getJSONObject(rc);
            for (String key : row.keySet()) {
                if (key.equals(featureName))
                    list.add(row.get(key).toString());
            }/*from  ww  w .j a v  a  2 s  .c  om*/
        }
    }
    return list;
}