Example usage for org.json JSONObject getLong

List of usage examples for org.json JSONObject getLong

Introduction

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

Prototype

public long getLong(String key) throws JSONException 

Source Link

Document

Get the long value associated with a key.

Usage

From source file:com.hichinaschool.flashcards.libanki.sync.Syncer.java

private void mergeModels(JSONArray rchg) {
    for (int i = 0; i < rchg.length(); i++) {
        try {//w ww .  ja v  a2s.c  om
            JSONObject r = rchg.getJSONObject(i);
            JSONObject l;
            l = mCol.getModels().get(r.getLong("id"));
            // if missing locally or server is newer, update
            if (l == null || r.getLong("mod") > l.getLong("mod")) {
                mCol.getModels().update(r);
            }
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.hichinaschool.flashcards.libanki.sync.Syncer.java

private void mergeDecks(JSONArray rchg) {
    try {/*from  w ww  .ja  va 2  s.c om*/
        JSONArray decks = rchg.getJSONArray(0);
        for (int i = 0; i < decks.length(); i++) {
            JSONObject r = decks.getJSONObject(i);
            JSONObject l = mCol.getDecks().get(r.getLong("id"), false);
            // if missing locally or server is newer, update
            if (l == null || r.getLong("mod") > l.getLong("mod")) {
                mCol.getDecks().update(r);
            }
        }
        JSONArray confs = rchg.getJSONArray(1);
        for (int i = 0; i < confs.length(); i++) {
            JSONObject r = confs.getJSONObject(i);
            JSONObject l = mCol.getDecks().getConf(r.getLong("id"));
            // if missing locally or server is newer, update
            if (l == null || r.getLong("mod") > l.getLong("mod")) {
                mCol.getDecks().updateConf(r);
            }
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.brennasoft.facebookdashclockextension.fbclient.InboxRequest.java

private InboxResponse parseResponse(Response response) {
    InboxResponse inboxResponse = new InboxResponse();
    GraphObject graphObject = response.getGraphObject();
    try {/*w  w  w .  ja  va  2 s  .com*/
        JSONArray data = graphObject.getInnerJSONObject().getJSONArray("data");
        if (data.length() == 2) {
            JSONArray messageResultSet = data.getJSONObject(0).getJSONArray("fql_result_set");
            JSONArray userResultSet = data.getJSONObject(1).getJSONArray("fql_result_set");
            if (messageResultSet.length() >= 1 && userResultSet.length() >= 1) {
                JSONObject message = messageResultSet.getJSONObject(0);
                String snippet = message.getString("snippet");
                Date time = new Date(message.getLong("updated_time") * 1000);
                String author = userResultSet.getJSONObject(0).getString("name");
                inboxResponse.snippet = snippet;
                inboxResponse.author = author;
                inboxResponse.time = time;
                inboxResponse.count = messageResultSet.length();
                inboxResponse.success = true;
            }
        }
    } catch (JSONException e) {
        Crashlytics.logException(e);
    }
    return inboxResponse;
}

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  . ja  v a2s .  c  o m
@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  . com
@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

@Override
public List<Project> getTodayProjectList(String searchText, String searchColumns, int startNum, int rowCount,
        String status) throws ResponseException {
    ReleasableList<Project> projectList = null;
    try {/*from   w  w w. j a  va  2s . c o m*/
        JSONObject params = new JSONObject();
        params.put("searchWord", searchText);
        params.put("searchColumns", searchColumns);
        params.put("startNum", startNum);
        params.put("rowCount", rowCount);
        params.put("status", status);
        params.put("searchType", "0");

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_TODAY_PROJECT_LIST), params, null);
        if (response.isSuccess()) {
            projectList = new ArrayReleasableList<Project>();
            JSONObject jsonBean = new JSONObject(getSimpleString(response));
            JSONArray array = jsonBean.getJSONArray("result");
            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(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(json.getString("brand"));
                purchaseCarIntention.setModelCode(json.getString("modelCode"));
                purchaseCarIntention.setModel(json.getString("model"));
                purchaseCarIntention.setFlowStatus(json.getString("flowStatus"));
                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"));
                purchaseCarIntention.setEmployeeName(json.getString("employeeName"));
                purchaseCarIntention.setCreateDate(parsingLong(json.getString("createDate")));

                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:com.roiland.crm.sm.core.service.impl.ProjectAPIImpl.java

@Override
public List<Project> getExpiredProjectList(String searchText, String searchColumns, int startNum, int rowCount)
        throws ResponseException {
    ReleasableList<Project> projectList = null;
    try {/*from ww w . jav  a  2  s . c  o m*/
        JSONObject params = new JSONObject();
        params.put("searchWord", searchText);
        params.put("searchColumns", searchColumns);
        params.put("startNum", startNum);
        params.put("rowCount", rowCount);
        params.put("searchType", "0");

        RLHttpResponse response = getHttpClient()
                .executePostJSON(getURLAddress(URLContact.METHOD_GET_EXPIRED_PROJECT_LIST), params, null);
        if (response.isSuccess()) {
            projectList = new ArrayReleasableList<Project>();
            JSONObject jsonBean = new JSONObject(getSimpleString(response));
            JSONArray array = jsonBean.getJSONArray("result");
            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(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(json.getString("brand"));
                purchaseCarIntention.setModelCode(json.getString("modelCode"));
                purchaseCarIntention.setModel(json.getString("model"));
                purchaseCarIntention.setFlowStatus(json.getString("flowStatus"));
                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"));
                purchaseCarIntention.setEmployeeName(json.getString("employeeName"));

                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:com.kwang.sunshine.FetchWeatherTask.java

/**
 * Take the String representing the complete forecast in JSON Format and
 * pull out the data we need to construct the Strings needed for the wireframes.
 *
 * Fortunately parsing is easy:  constructor takes the JSON string and converts it
 * into an Object hierarchy for us.//from   www . java2 s  . c  o m
 */
private String[] getWeatherDataFromJson(String forecastJsonStr, int numDays, String locationSetting)
        throws JSONException {

    // These are the names of the JSON objects that need to be extracted.

    // Location information
    final String OWM_CITY = "city";
    final String OWM_CITY_NAME = "name";
    final String OWM_COORD = "coord";
    final String OWM_COORD_LAT = "lat";
    final String OWM_COORD_LONG = "lon";

    // Weather information.  Each day's forecast info is an element of the "list" array.
    final String OWM_LIST = "list";

    final String OWM_DATETIME = "dt";
    final String OWM_PRESSURE = "pressure";
    final String OWM_HUMIDITY = "humidity";
    final String OWM_WINDSPEED = "speed";
    final String OWM_WIND_DIRECTION = "deg";

    // All temperatures are children of the "temp" object.
    final String OWM_TEMPERATURE = "temp";
    final String OWM_MAX = "max";
    final String OWM_MIN = "min";

    final String OWM_WEATHER = "weather";
    final String OWM_DESCRIPTION = "main";
    final String OWM_WEATHER_ID = "id";

    JSONObject forecastJson = new JSONObject(forecastJsonStr);
    JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST);

    JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY);
    String cityName = cityJson.getString(OWM_CITY_NAME);
    JSONObject coordJSON = cityJson.getJSONObject(OWM_COORD);
    double cityLatitude = coordJSON.getLong(OWM_COORD_LAT);
    double cityLongitude = coordJSON.getLong(OWM_COORD_LONG);

    Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude);

    // Insert the location into the database.
    long locationID = addLocation(locationSetting, cityName, cityLatitude, cityLongitude);

    // Get and insert the new weather information into the database
    Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length());

    String[] resultStrs = new String[numDays];

    for (int i = 0; i < weatherArray.length(); i++) {
        // These are the values that will be collected.

        long dateTime;
        double pressure;
        int humidity;
        double windSpeed;
        double windDirection;

        double high;
        double low;

        String description;
        int weatherId;

        // Get the JSON object representing the day
        JSONObject dayForecast = weatherArray.getJSONObject(i);

        // The date/time is returned as a long.  We need to convert that
        // into something human-readable, since most people won't read "1400356800" as
        // "this saturday".
        dateTime = dayForecast.getLong(OWM_DATETIME);

        pressure = dayForecast.getDouble(OWM_PRESSURE);
        humidity = dayForecast.getInt(OWM_HUMIDITY);
        windSpeed = dayForecast.getDouble(OWM_WINDSPEED);
        windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION);

        // Description is in a child array called "weather", which is 1 element long.
        // That element also contains a weather code.
        JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0);
        description = weatherObject.getString(OWM_DESCRIPTION);
        weatherId = weatherObject.getInt(OWM_WEATHER_ID);

        // Temperatures are in a child object called "temp".  Try not to name variables
        // "temp" when working with temperature.  It confuses everybody.
        JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE);
        high = temperatureObject.getDouble(OWM_MAX);
        low = temperatureObject.getDouble(OWM_MIN);

        ContentValues weatherValues = new ContentValues();

        weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationID);
        weatherValues.put(WeatherEntry.COLUMN_DATETEXT,
                WeatherContract.getDbDateString(new Date(dateTime * 1000L)));
        weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity);
        weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure);
        weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed);
        weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection);
        weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high);
        weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low);
        weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description);
        weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId);

        cVVector.add(weatherValues);

        String highAndLow = formatHighLows(high, low);
        String day = getReadableDateString(dateTime);
        resultStrs[i] = day + " - " + description + " - " + highAndLow;
    }

    if (cVVector.size() > 0) {
        ContentValues[] cvArray = new ContentValues[cVVector.size()];
        cVVector.toArray(cvArray);
        int rowsInserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray);
        Log.v(LOG_TAG, "inserted " + rowsInserted + " rows of weather data");
        // Use a DEBUG variable to gate whether or not you do this, so you can easily
        // turn it on and off, and so that it's easy to see what you can rip out if
        // you ever want to remove it.
        if (DEBUG) {
            Cursor weatherCursor = mContext.getContentResolver().query(WeatherEntry.CONTENT_URI, null, null,
                    null, null);

            if (weatherCursor.moveToFirst()) {
                ContentValues resultValues = new ContentValues();
                DatabaseUtils.cursorRowToContentValues(weatherCursor, resultValues);
                Log.v(LOG_TAG, "Query succeeded! **********");
                for (String key : resultValues.keySet()) {
                    Log.v(LOG_TAG, key + ": " + resultValues.getAsString(key));
                }
            } else {
                Log.v(LOG_TAG, "Query failed! :( **********");
            }
        }
    }

    return resultStrs;
}

From source file:jfabrix101.billing.BillingSecurity.java

/**
 * Verifies that the data was signed with the given signature, and returns
 * the list of verified purchases. The data is in JSON format and contains
 * a nonce (number used once) that we generated and that was signed
 * (as part of the whole data string) with a private key. The data also
 * contains the {@link PurchaseState} and product ID of the purchase.
 * In the general case, there can be an array of purchase transactions
 * because there may be delays in processing the purchase on the backend
 * and then several purchases can be batched together.
 * @param signedData the signed JSON string (signed, not encrypted)
 * @param signature the signature for the data, signed with the private key
 *///ww w. j a  v  a2 s  .  c o m
public static ArrayList<VerifiedPurchase> verifyPurchase(Context context, String signedData, String signature) {
    if (signedData == null) {
        Log.e(TAG, "data is null");
        return null;
    }
    if (BillingConsts.DEBUG) {
        Log.i(TAG, "signedData: " + signedData);
    }
    boolean verified = false;
    if (!TextUtils.isEmpty(signature)) {
        /**
         * Compute your public key (that you got from the Android Market publisher site).
         *
         * Instead of just storing the entire literal string here embedded in the
         * program,  construct the key at runtime from pieces or
         * use bit manipulation (for example, XOR with some other string) to hide
         * the actual key.  The key itself is not secret information, but we don't
         * want to make it easy for an adversary to replace the public key with one
         * of their own and then fake messages from the server.
         *
         * Generally, encryption keys / passwords should only be kept in memory
         * long enough to perform the operation they need to perform.
         */

        SharedPreferences pref = context.getSharedPreferences("billingPK", 0);
        AESObfuscator obfuscator = AESObfuscator.getDefaultObfuscator(context);
        String publicKey = "";
        try {
            publicKey = obfuscator.unobfuscate(pref.getString("pk", ""));
        } catch (Exception e) {
            Log.e(TAG, "Error getting publicc key from repository");
            return null;
        }
        PublicKey key = BillingSecurity.generatePublicKey(publicKey);
        verified = BillingSecurity.verify(key, signedData, signature);
        if (!verified) {
            Log.w(TAG, "signature does not match data.");
            return null;
        }
    }

    JSONObject jObject;
    JSONArray jTransactionsArray = null;
    int numTransactions = 0;
    long nonce = 0L;
    try {
        jObject = new JSONObject(signedData);

        // The nonce might be null if the user backed out of the buy page.
        nonce = jObject.optLong("nonce");
        jTransactionsArray = jObject.optJSONArray("orders");
        if (jTransactionsArray != null) {
            numTransactions = jTransactionsArray.length();
        }
    } catch (JSONException e) {
        return null;
    }

    if (!BillingSecurity.isNonceKnown(nonce)) {
        Log.w(TAG, "Nonce not found: " + nonce);
        return null;
    }

    ArrayList<VerifiedPurchase> purchases = new ArrayList<VerifiedPurchase>();
    try {
        for (int i = 0; i < numTransactions; i++) {
            JSONObject jElement = jTransactionsArray.getJSONObject(i);
            int response = jElement.getInt("purchaseState");
            PurchaseState purchaseState = PurchaseState.valueOf(response);
            String productId = jElement.getString("productId");
            //String packageName = jElement.getString("packageName");
            long purchaseTime = jElement.getLong("purchaseTime");
            String orderId = jElement.optString("orderId", "");
            String notifyId = null;
            if (jElement.has("notificationId")) {
                notifyId = jElement.getString("notificationId");
            }
            String developerPayload = jElement.optString("developerPayload", null);

            // If the purchase state is PURCHASED, then we require a verified nonce.
            if (purchaseState == PurchaseState.PURCHASED && !verified) {
                continue;
            }
            purchases.add(new VerifiedPurchase(purchaseState, notifyId, productId, orderId, purchaseTime,
                    developerPayload));
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception: ", e);
        return null;
    }
    removeNonce(nonce);
    return purchases;
}

From source file:cn.code.notes.gtask.data.TaskList.java

public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {// w  w w.j  a  v  a2s  . c o  m
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get tasklist content from jsonobject");
        }
    }
}