Example usage for org.json JSONArray toString

List of usage examples for org.json JSONArray toString

Introduction

In this page you can find the example usage for org.json JSONArray toString.

Prototype

public String toString() 

Source Link

Document

Make a JSON text of this JSONArray.

Usage

From source file:streamme.data.FolderStructure.java

public String getJSON() {
    JSONArray main = new JSONArray();
    for (Folder f : structure) {
        main.put(getJSON(f));/*  www.  jav  a2  s  .  c  o m*/
    }
    return main.toString();
}

From source file:com.abeo.tia.noordin.ProcessCaseProperty.java

private void confirm_values() throws JSONException {
    System.out.print(jsonResponseconfirm);
    // TODO Auto-generated method stub 
    //         String json_element = "[{\"Case\":\"1500000001\",\"CaseType\":\"SPA-BUY-DEV-APT-C\",\"CaseStatus\":\"OPEN\",\"FileOpenDate\":\"10/10/2015 12:00:00 AM\",\"CaseFileNo\":\"JJ/1500000001/\",\"KIV\":\"\",\"TabId\":\"2\",\"Details\":{\"LA\":\"\",\"MANAGER\":\"\",\"InCharge\":\"\",\"CustomerService\":\"\",\"CaseType\":\"SPA-BUY-DEV-APT-C\",\"FileLocation\":\"\",\"FileClosedDate\":\"\",\"VendAcqDt\":\"\",\"CompanyBuisnessSearch\":\"\",\"BankWindingSearch\":\"\"},\"Purchaser\":{\"PurRepresentedByFirm\":\"N\",\"PurlawyerRepresented\":\"N\",\"PurSPADate\":\"1/1/1900 12:00:00 AM\",\"PurEntryOfPrivateCaveat\":\"Chase\",\"PurWithOfPrivateCaveat\":\"Rane\",\"PurFirstName\":\"Name1\",\"PurFirstID\":\"Id1\",\"PurFirstTaxNo\":\"Tax1\",\"PurFirstContactNo\":\"9784561233\",\"PurFirstType\":\"CORPORATE\",\"PurSecName\":\"Name2\",\"PurSecID\":\"Id2\",\"PurSecTaxNo\":\"Tax2\",\"PurSecContactNo\":\"9784561234\",\"PurSecType\":\"INDIVIDUAL\",\"PurThirdName\":\"Name3\",\"PurThirdID\":\"Id3\",\"PurThirdTaxNo\":\"Tax3\",\"PurThirdContactNo\":\"9784561234\",\"PurThirdType\":\"INDIVIDUAL\",\"PurFourthName\":\"Name4\",\"PurFourthID\":\"Id4\",\"PurFourthTaxNo\":\"Tax4\",\"PurFourthContactNo\":\"9784561235\",\"PurFourthType\":\"INDIVIDUAL\"},\"Vendor\":{\"VndrRepresentedByFirm\":\"N\",\"VndrlawyerRepresented\":\"Y\",\"VndrReqDevConsent\":\"Name\",\"VndrReceiveDevConsent\":\"Sam\",\"VndrFirstName\":\"Name1\",\"VndrFirstID\":\"Id1\",\"VndrFirstTaxNo\":\"Tax1\",\"VndrFirstContactNo\":\"9784561233\",\"VndrFirstType\":\"CORPORATE\",\"VndrSecName\":\"Name2\",\"VndrSecID\":\"Id2\",\"VndrSecTaxNo\":\"Tax2\",\"VndrSecContactNo\":\"9784561234\",\"VndrSecType\":\"INDIVIDUAL\",\"VndrThirdName\":\"Name3\",\"VndrThirdID\":\"Id3\",\"VndrThirdTaxNo\":\"Tax3\",\"VndrThirdContactNo\":\"9784561234\",\"VndrThirdType\":\"INDIVIDUAL\",\"VndrFourthName\":\"Name4\",\"VndrFourthID\":\"Id4\",\"VndrFourthTaxNo\":\"Tax4\",\"VndrFourthContactNo\":\"9784561235\",\"VndrFourthType\":\"INDIVIDUAL\"},\"Property\":{\"TitleType\":\"KEKAL\",\"CertifiedPlanNo\":\"\",\"LotNo\":\"\",\"PreviouslyKnownAs\":\"\",\"State\":\"\",\"Area\":\"\",\"BPM\":\"\",\"GovSurvyPlan\":\"\",\"LotArea\":\"12345\",\"Developer\":\"\",\"Project\":\"\",\"DevLicenseNo\":\"\",\"DevSolicitor\":\"\",\"DevSoliLoc\":\"\",\"TitleSearchDate\":\"\",\"DSCTransfer\":\"\",\"DRCTransfer\":\"\",\"FourteenADate\":\"\",\"DRTLRegistry\":\"\",\"PropertyCharged\":\"\",\"BankName\":\"\",\"Branch\":\"\",\"PAName\":\"\",\"PresentationNo\":\"\",\"ExistChargeRef\":\"\",\"ReceiptType\":\"\",\"ReceiptNo\":\"\",\"ReceiptDate\":\"\",\"PurchasePrice\":\"1452\",\"AdjValue\":\"\",\"VndrPrevSPAValue\":\"\",\"Deposit\":\"\",\"BalPurPrice\":\"\",\"LoanAmount\":\"\",\"LoanCaseNo\":\"1234\",\"DiffSum\":\"\",\"RedAmt\":\"\",\"RedDate\":\"\",\"DefRdmptSum\":\"\"},\"LoanPrinciple\":{\"ReqRedStatement\":\"\",\"RedStmtDate\":\"\",\"RedPayDate\":\"\",\"RepByFirm\":\"\",\"LoanCaseNo\":\"1234\",\"Project\":\"\",\"MasterBankName\":\"\",\"BranchName\":\"\",\"Address\":\"\",\"PAName\":\"\",\"BankRef\":\"\",\"BankInsDate\":\"2015/10/11\",\"LOFDate\":\"\",\"BankSolicitor\":\"\",\"SoliLoc\":\"\",\"SoliRef\":\"\",\"TypeofLoan\":\"\",\"TypeofFacility\":\"\",\"FacilityAmt\":\"\",\"Repaymt\":\"\",\"IntrstRate\":\"\",\"MonthlyInstmt\":\"\",\"TermLoanAmt\":\"\",\"Interest\":\"\",\"ODLoan\":\"\",\"MRTA\":\"\",\"BankGuarantee\":\"\",\"LetterofCredit\":\"\",\"TrustReceipt\":\"\",\"Others\":\"\",\"LoanDet1\":\"\",\"LoanDet2\":\"\",\"LoanDet3\":\"\",\"LoanDet4\":\"\",\"LoanDet5\":\"\"},\"LoanSubsidary\":{\"LoanDocForBankExe\":\"Exe 1\",\"FaciAgreeDate\":\"\",\"LoanDocRetFromBank\":\"\",\"DischargeofCharge\":\"\",\"FirstTypeofFacility\":\"\",\"FirstFacilityAmt\":\"\",\"FirstRepaymt\":\"\",\"FirstIntrstRate\":\"\",\"FirstMonthlyInstmt\":\"1500\",\"FirstTermLoanAmt\":\"\",\"FirstInterest\":\"\",\"FirstODLoan\":\"\",\"FirstMRTA\":\"\",\"FirstBankGuarantee\":\"\",\"FirstLetterofCredit\":\"\",\"FirstTrustReceipt\":\"\",\"FirstOthers\":\"Sample\",\"SecTypeofFacility\":\"\",\"SecFacilityAmt\":\"\",\"SecRepaymt\":\"\",\"SecIntrstRate\":\"12%\",\"SecMonthlyInstmt\":\"\",\"SecTermLoanAmt\":\"\",\"SecInterest\":\"\",\"SecODLoan\":\"\",\"SecMRTA\":\"\",\"SecBankGuarantee\":\"\",\"SecLetterofCredit\":\"\",\"SecTrustReceipt\":\"45A\",\"SecOthers\":\"\",\"ThirdTypeofFacility\":\"Sample_Data\",\"ThirdFacilityAmt\":\"\",\"ThirdRepaymt\":\"\",\"ThirdIntrstRate\":\"\",\"ThirdMonthlyInstmt\":\"\",\"ThirdTermLoanAmt\":\"587.15\",\"ThirdInterest\":\"\",\"ThirdODLoan\":\"\",\"ThirdMRTA\":\"\",\"ThirdBankGuarantee\":\"\",\"ThirdLetterofCredit\":\"\",\"ThirdTrustReceipt\":\"\",\"ThirdOthers\":\"\",\"FourthTypeofFacility\":\"Sample4\",\"FourthFacilityAmt\":\"\",\"FourthRepaymt\":\"15\",\"FourthIntrstRate\":\"\",\"FourthMonthlyInstmt\":\"\",\"FourthTermLoanAmt\":\"\",\"FourthInterest\":\"21\",\"FourthODLoan\":\"\",\"FourthMRTA\":\"\",\"FourthBankGuarantee\":\"\",\"FourthLetterofCredit\":\"\",\"FourthTrustReceipt\":\"\",\"FourthOthers\":\"\",\"FifthTypeofFacility\":\"Sample 5\",\"FifthFacilityAmt\":\"\",\"FifthRepaymt\":\"\",\"FifthIntrstRate\":\"\",\"FifthMonthlyInstmt\":\"\",\"FifthTermLoanAmt\":\"\",\"FifthInterest\":\"10\",\"FifthODLoan\":\"\",\"FifthMRTA\":\"\",\"FifthBankGuarantee\":\"\",\"FifthLetterofCredit\":\"\",\"FifthTrustReceipt\":\"Test\",\"FifthOthers\":\"\"}}]";
    String json_element = "[{\"Case\":" + "\"" + jsonResponseconfirm.get("Case").toString() + "\",\"CaseType\":"
            + "\"" + jsonResponseconfirm.get("CaseType").toString()
            + "\",\"CaseStatus\":\"OPEN\",\"FileOpenDate\":\"10/10/2015 12:00:00 AM\",\"CaseFileNo\":" + "\""
            + jsonResponseconfirm.get("CaseFileNo").toString()
            + "\",\"KIV\":\"\",\"TabId\":\"4\",\"Details\":{\"LA\":\"\",\"MANAGER\":\"\",\"InCharge\":\"\",\"CustomerService\":\"\",\"CaseType\":\"SPA-BUY-DEV-APT-C\",\"FileLocation\":\"\",\"FileClosedDate\":\"\",\"VendAcqDt\":\"\",\"CompanyBuisnessSearch\":\"\",\"BankWindingSearch\":\"\"},\"Purchaser\":{\"PurRepresentedByFirm\":\"N\",\"PurlawyerRepresented\":\"N\",\"PurSPADate\":\"1/1/1900 12:00:00 AM\",\"PurEntryOfPrivateCaveat\":\"Chase\",\"PurWithOfPrivateCaveat\":\"Rane\",\"PurFirstName\":\"Name1\",\"PurFirstID\":\"Id1\",\"PurFirstTaxNo\":\"Tax1\",\"PurFirstContactNo\":\"9784561233\",\"PurFirstType\":\"CORPORATE\",\"PurSecName\":\"Name2\",\"PurSecID\":\"Id2\",\"PurSecTaxNo\":\"Tax2\",\"PurSecContactNo\":\"9784561234\",\"PurSecType\":\"INDIVIDUAL\",\"PurThirdName\":\"Name3\",\"PurThirdID\":\"Id3\",\"PurThirdTaxNo\":\"Tax3\",\"PurThirdContactNo\":\"9784561234\",\"PurThirdType\":\"INDIVIDUAL\",\"PurFourthName\":\"Name4\",\"PurFourthID\":\"Id4\",\"PurFourthTaxNo\":\"Tax4\",\"PurFourthContactNo\":\"9784561235\",\"PurFourthType\":\"INDIVIDUAL\"},\"Vendor\":{\"VndrRepresentedByFirm\":\"N\",\"VndrlawyerRepresented\":\"Y\",\"VndrReqDevConsent\":\"Name\",\"VndrReceiveDevConsent\":\"Sam\",\"VndrFirstName\":\"Name1\",\"VndrFirstID\":\"Id1\",\"VndrFirstTaxNo\":\"Tax1\",\"VndrFirstContactNo\":\"9784561233\",\"VndrFirstType\":\"CORPORATE\",\"VndrSecName\":\"Name2\",\"VndrSecID\":\"Id2\",\"VndrSecTaxNo\":\"Tax2\",\"VndrSecContactNo\":\"9784561234\",\"VndrSecType\":\"INDIVIDUAL\",\"VndrThirdName\":\"Name3\",\"VndrThirdID\":\"Id3\",\"VndrThirdTaxNo\":\"Tax3\",\"VndrThirdContactNo\":\"9784561234\",\"VndrThirdType\":\"INDIVIDUAL\",\"VndrFourthName\":\"Name4\",\"VndrFourthID\":\"Id4\",\"VndrFourthTaxNo\":\"Tax4\",\"VndrFourthContactNo\":\"9784561235\",\"VndrFourthType\":\"INDIVIDUAL\"},\"Property\":{\""
            + "TitleType" + "\":" + "\"" + title_no.getText().toString() + "\",\"PropertyCharged\":" + "\""
            + QryGroup13.isChecked() + "\",\"QryGroup14\":" + "\"" + QryGroup14 + "\",\"QryGroup15\":" + "\""
            + QryGroup15 + "\",\"QryGroup16\":" + "\"" + QryGroup16 + "\",\"" + "CertifiedPlanNo" + "\":"
            + "\"\",\"" + "LotNo" + "\":" + "\"" + no_lot.getText().toString() + "\",\"" + "PreviouslyKnownAs"
            + "\":" + "\"" + previously_knowas.getText().toString() + "\",\"" + "State" + "\":" + "\""
            + stateval + "\",\"" + "Area" + "\":" + "\"" + area.getText().toString() + "\",\"" + "ReceiptNo"
            + "\": " + "\"" + receipt_no.getText().toString() + "\",\"" + "BPM" + "\":" + "\""
            + bandar_mukin.getText().toString() + "\",\"" + "GovSurvyPlan" + "\":" + "\"\",\"" + "LotArea"
            + "\":" + "\"" + lot_area.getText().toString() + "\",\"" + "Developer" + "\":" + "\""
            + developer.getText().toString() + "\",\"" + "Project" + "\":" + "\"" + project.getText().toString()
            + "\",\"" + "DevLicenseNo" + "\":" + "\"" + dev_license_no.getText().toString() + "\",\""
            + "DevSolicitor" + "\":" + "\"" + dev_solicitor.getText().toString() + "\",\"" + "DevSoliLoc"
            + "\":" + "\"" + soli_loc.getText().toString() + "\",\"" + "TitleSearchDate" + "\":" + "\""
            + title_search.getText().toString() + "\",\"" + "DSCTransfer" + "\":" + "\""
            + date_submit_consent.getText().toString() + "\",\"" + "DRCTransfer" + "\":" + "\""
            + date_receive_consent.getText().toString() + "\",\"" + "FourteenADate" + "\":" + "\""
            + date14_a.getText().toString() + "\",\"" + "DRTLRegistry" + "\":" + "\""
            + date_of_return.getText().toString() + "\",\"" + "BankName" + "\":" + "\""
            + bank_name.getText().toString() + "\",\"" + "Branch" + "\":" + "\"" + branch.getText().toString()
            + "\",\"" + "PAName" + "\":" + "\"" + pa_name.getText().toString() + "\",\"" + "PresentationNo"
            + "\":" + "\"" + presentation_no.getText().toString() + "\",\"" + "ExistChargeRef" + "\":" + "\""
            + existing_charge_refs.getText().toString() + "\",\"ReceiptType\":" + "\"" + Receipttype_val
            + "\",\"ReceiptDate" + "\":" + "\"" + receipt_date.getText().toString() + "\",\"" + "PurchasePrice"
            + "\":" + "\"" + purchase_price.getText().toString() + "\",\"" + "AdjValue" + "\":" + "\""
            + adjudicated_value.getText().toString() + "\",\"" + "VndrPrevSPAValue" + "\":" + "\""
            + vendor_prev.getText().toString() + "\",\"" + "Deposit" + "\":" + "\""
            + deposit.getText().toString() + "\",\"" + "BalPurPrice" + "\":" + "\""
            + balance_pur_price.getText().toString() + "\",\"" + "LoanAmount" + "\":" + "\""
            + loan_amt.getText().toString() + "\",\"" + "LoanCaseNo" + "\":" + "\""
            + loan_case_no.getText().toString() + "\",\"" + "DiffSum" + "\":" + "\""
            + differential_sum.getText().toString() + "\",\"" + "RedAmt" + "\":" + "\""
            + redemption_amt.getText().toString() + "\",\"" + "RedDate" + "\":" + "\""
            + redemption_date.getText().toString() + "\",\"" + "DefRdmptSum" + "\":" + "\""
            + defict_rdmt_sum.getText().toString()
            + "\"},\"LoanPrinciple\":{\"ReqRedStatement\":\"\",\"RedStmtDate\":\"\",\"RedPayDate\":\"\",\"RepByFirm\":\"\",\"LoanCaseNo\":\"1234\",\"Project\":\"\",\"MasterBankName\":\"\",\"BranchName\":\"\",\"Address\":\"\",\"PAName\":\"\",\"BankRef\":\"\",\"BankInsDate\":\"2015/10/11\",\"LOFDate\":\"\",\"BankSolicitor\":\"\",\"SoliLoc\":\"\",\"SoliRef\":\"\",\"TypeofLoan\":\"\",\"TypeofFacility\":\"\",\"FacilityAmt\":\"\",\"Repaymt\":\"\",\"IntrstRate\":\"\",\"MonthlyInstmt\":\"\",\"TermLoanAmt\":\"\",\"Interest\":\"\",\"ODLoan\":\"\",\"MRTA\":\"\",\"BankGuarantee\":\"\",\"LetterofCredit\":\"\",\"TrustReceipt\":\"\",\"Others\":\"\",\"LoanDet1\":\"\",\"LoanDet2\":\"\",\"LoanDet3\":\"\",\"LoanDet4\":\"\",\"LoanDet5\":\"\"},\"LoanSubsidary\":{\"LoanDocForBankExe\":\"Exe 1\",\"FaciAgreeDate\":\"\",\"LoanDocRetFromBank\":\"\",\"DischargeofCharge\":\"\",\"FirstTypeofFacility\":\"\",\"FirstFacilityAmt\":\"\",\"FirstRepaymt\":\"\",\"FirstIntrstRate\":\"\",\"FirstMonthlyInstmt\":\"1500\",\"FirstTermLoanAmt\":\"\",\"FirstInterest\":\"\",\"FirstODLoan\":\"\",\"FirstMRTA\":\"\",\"FirstBankGuarantee\":\"\",\"FirstLetterofCredit\":\"\",\"FirstTrustReceipt\":\"\",\"FirstOthers\":\"Sample\",\"SecTypeofFacility\":\"\",\"SecFacilityAmt\":\"\",\"SecRepaymt\":\"\",\"SecIntrstRate\":\"12%\",\"SecMonthlyInstmt\":\"\",\"SecTermLoanAmt\":\"\",\"SecInterest\":\"\",\"SecODLoan\":\"\",\"SecMRTA\":\"\",\"SecBankGuarantee\":\"\",\"SecLetterofCredit\":\"\",\"SecTrustReceipt\":\"45A\",\"SecOthers\":\"\",\"ThirdTypeofFacility\":\"Sample_Data\",\"ThirdFacilityAmt\":\"\",\"ThirdRepaymt\":\"\",\"ThirdIntrstRate\":\"\",\"ThirdMonthlyInstmt\":\"\",\"ThirdTermLoanAmt\":\"587.15\",\"ThirdInterest\":\"\",\"ThirdODLoan\":\"\",\"ThirdMRTA\":\"\",\"ThirdBankGuarantee\":\"\",\"ThirdLetterofCredit\":\"\",\"ThirdTrustReceipt\":\"\",\"ThirdOthers\":\"\",\"FourthTypeofFacility\":\"Sample4\",\"FourthFacilityAmt\":\"\",\"FourthRepaymt\":\"15\",\"FourthIntrstRate\":\"\",\"FourthMonthlyInstmt\":\"\",\"FourthTermLoanAmt\":\"\",\"FourthInterest\":\"21\",\"FourthODLoan\":\"\",\"FourthMRTA\":\"\",\"FourthBankGuarantee\":\"\",\"FourthLetterofCredit\":\"\",\"FourthTrustReceipt\":\"\",\"FourthOthers\":\"\",\"FifthTypeofFacility\":\"Sample 5\",\"FifthFacilityAmt\":\"\",\"FifthRepaymt\":\"\",\"FifthIntrstRate\":\"\",\"FifthMonthlyInstmt\":\"\",\"FifthTermLoanAmt\":\"\",\"FifthInterest\":\"10\",\"FifthODLoan\":\"\",\"FifthMRTA\":\"\",\"FifthBankGuarantee\":\"\",\"FifthLetterofCredit\":\"\",\"FifthTrustReceipt\":\"Test\",\"FifthOthers\":\"\"}}]";
    Log.e("pur_string", json_element);

    JSONObject valuesObject = null;/*from  w  w w.  j a va 2s .  co m*/
    JSONArray list = null;
    try {
        list = new JSONArray(json_element);
        valuesObject = list.getJSONObject(0);

        /*valuesObject.put("PurSPADate",spa_date.getText().toString());
        valuesObject.put("PurEntryOfPrivateCaveat", entry_private_caveat.getText().toString());
        valuesObject.put("PurWithOfPrivateCaveat", withdrawal_private_caveat.getText().toString());
        valuesObject.put("PurFirstName", name1.getText().toString());
        valuesObject.put("PurFirstID", brn_no1.getText().toString());
        valuesObject.put("PurFirstTaxNo", tax_no1.getText().toString());
        valuesObject.put("PurFirstContactNo", contact_no1.getText().toString());*/

        list.put(valuesObject);

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    RequestParams params = new RequestParams();
    params.put("sJsonInput", list.toString());
    System.out.println("params Data Property confirm");
    System.out.println("params");

    RestService.post(CONFIRM_BTN_REQUEST, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("onFailure process case purchaser");
        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Add purchaser Confirmed");
            System.out.println(arg2);

            // Find status Response
            try {
                StatusResult = jsonResponse.getString("Result").toString();
                messageDisplay = jsonResponse.getString("DisplayMessage").toString();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (StatusResult.equals("SUCCESS")) {
                Intent iAddBack = new Intent(ProcessCaseProperty.this, ProcessCaseLoanPrincipal.class);
                startActivity(iAddBack);
                Toast.makeText(ProcessCaseProperty.this, messageDisplay, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(ProcessCaseProperty.this, messageDisplay, Toast.LENGTH_SHORT).show();

            }
        }

        @Override
        protected String parseResponse(String arg0, boolean arg1) throws Throwable {

            // Get Json response
            arrayResponse = new JSONArray(arg0);
            jsonResponse = arrayResponse.getJSONObject(0);

            System.out.println("Purchaser Add Response");
            System.out.println(arg0);
            return null;
        }
    });
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

/**
 * Like org.json.JSONArray except that it doesn't escape forward slashes
 * The necessity for this method is due to python's 2.7 json.dumps() function that doesn't escape chracter '/'.
 * The org.json.JSONArray parser accepts both escaped and unescaped forward slashes, so we only need to worry for
 * our output, when we write to the database or syncing.
 *
 * @param json a json object to serialize
 * @return the json serialization of the object
 * @see org.json.JSONArray#toString()//from  w w  w  .  j a  va  2 s .co m
 */
public static String jsonToString(JSONArray json) {
    return json.toString().replaceAll("\\\\/", "/");
}

From source file:com.rapid.actions.Validation.java

@Override
public String getJavaScript(RapidRequest rapidRequest, Application application, Page page, Control control,
        JSONObject jsonDetails) throws Exception {

    String js = "";

    // check we have some controls
    if (_controls != null) {
        // the validations is a JavaScript array
        JSONArray jsonValidations = new JSONArray();
        // loop the controls (which are actually controlIds)
        for (String controlId : _controls) {
            // find the control proper
            Control validateControl = page.getControl(controlId);
            // check we have a control
            if (validateControl != null) {
                // get the control validation
                com.rapid.core.Validation controlValidation = validateControl.getValidation();
                // check there is control validation
                if (controlValidation != null) {

                    // find the control class
                    JSONObject jsonControl = rapidRequest.getRapidServlet()
                            .getJsonControl(validateControl.getType());

                    // check a type has been specified and we could find it
                    if (jsonControl != null && !"".equals(controlValidation.getType())) {
                        // this method can't throw so catch here               
                        try {

                            // build the validations object
                            JSONObject jsonValidation = new JSONObject();

                            // add the properties                  
                            jsonValidation.put("controlId", validateControl.getId());
                            jsonValidation.put("controlType", validateControl.getType());
                            jsonValidation.put("validationType", controlValidation.getType());
                            jsonValidation.put("message", controlValidation.getMessage());
                            jsonValidation.put("validationProperty", jsonControl.opt("validationProperty"));
                            if (!"".equals(controlValidation.getRegEx()))
                                jsonValidation.put("regEx", controlValidation.getRegEx());
                            if (!"".equals(controlValidation.getJavaScript()))
                                jsonValidation.put("javaScript", controlValidation.getJavaScript());
                            if (controlValidation.getPassHidden())
                                jsonValidation.put("passHidden", true);
                            if (controlValidation.getAllowNulls())
                                jsonValidation.put("allowNulls", true);

                            // add optional properties
                            if (validateControl.getDetails() != null)
                                jsonValidation.put("details",
                                        validateControl.getDetailsJavaScript(application, page));

                            // add it to the array
                            jsonValidations.put(jsonValidation);

                        } catch (JSONException ex) {
                        }/*w  w w  .  j  av a  2 s  . co m*/
                    }
                }
            }
        }
        js = "if (Action_validation(ev, " + jsonValidations.toString() + "," + getProperty("showMessages")
                + ")) {\n";

        // insert pass actions
        if (_passActions != null) {
            for (Action action : _passActions)
                js += "  " + action.getJavaScript(rapidRequest, application, page, control, jsonDetails) + "\n";
        }

        js += "} else {\n";

        // insert fail actions
        if (_failActions != null) {
            for (Action action : _failActions)
                js += "  " + action.getJavaScript(rapidRequest, application, page, control, jsonDetails) + "\n";
        }

        // check whether to stop further actions
        boolean stopActions = Boolean.parseBoolean(getProperty("stopActions"));
        if (stopActions)
            js += "  return false;\n";

        js += "}\n";
    }

    return js;

}

From source file:com.reignite.parser.QueryParser.java

private Criterion createAnd(JSONArray ands, int index) throws ParserException {
    if (ands.length() == (index + 1)) {
        try {/*from  w ww .j  a  v a  2 s .  c  o m*/
            return createCriterion(ands.getJSONObject(index));
        } catch (JSONException e) {
            throw new ParserException(
                    "and clauses must be arrays with at least two elements: " + ands.toString());
        }
    }
    JSONObject andObj = null;
    try {
        andObj = ands.getJSONObject(index);
    } catch (JSONException e) {
        throw new ParserException("each element of an and clause must be a JSON Object. " + query.toString());
    }
    return Restrictions.and(createCriterion(andObj), createAnd(ands, index + 1));
}

From source file:com.reignite.parser.QueryParser.java

private Criterion createOr(JSONArray ors, int index) throws ParserException {
    if (ors.length() == (index + 1)) {
        try {/*from  ww  w . j a  v a  2s . c o  m*/
            return createCriterion(ors.getJSONObject(index));
        } catch (JSONException e) {
            throw new ParserException(
                    "or clauses must be arrays with at least two elements: " + ors.toString());
        }
    }
    JSONObject orObj = null;
    try {
        orObj = ors.getJSONObject(index);
    } catch (JSONException e) {
        throw new ParserException("each element of an or clause must be a JSON Object. " + query.toString());
    }
    return Restrictions.or(createCriterion(orObj), createOr(ors, index + 1));
}

From source file:com.c4fcm.actionpath.SimpleGeofenceStore.java

protected void commitGeofenceStoreKeys() {
    JSONArray geofenceStoreKeysJSON = new JSONArray(geofenceStoreKeys);
    Editor editor = mPrefs.edit();//from w w w  . j a va  2  s .  c om

    // Write the Geofence values to SharedPreferences
    editor.putString("GEOFENCE_STORE_KEYS", geofenceStoreKeysJSON.toString());
    editor.commit();
}

From source file:com.pseudosudostudios.jdd.utils.ScoreSaves.java

private static void writeFile(Context c, List<Entry> entries) {
    Collections.sort(entries);/*from w  w w .  jav a  2s  .  c  om*/
    File file = new File(c.getFilesDir(), fileName);
    try {
        file.createNewFile();
        JSONArray array = new JSONArray();
        for (Entry e : entries)
            array.put(makeJSONObject(e));
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.write(array.toString());
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}

From source file:waveimport.RobotApi.java

private JSONObject callRobotApi(String method, Map<String, Object> params) throws IOException {
    JSONArray ops = new JSONArray();
    try {/*  w  w w. ja  va 2s  .co  m*/
        JSONObject jsonParams = new JSONObject();
        for (Map.Entry<String, Object> e : params.entrySet()) {
            jsonParams.put(e.getKey(), e.getValue());
        }
        JSONObject op = new JSONObject();
        op.put("params", jsonParams);
        op.put("method", method);
        op.put("id", OP_ID);
        ops.put(op);
    } catch (JSONException e) {
        throw new RuntimeException("Failed to construct JSON object", e);
    }
    HTTPRequest req = new HTTPRequest(new URL(baseUrl), HTTPMethod.POST,
            FetchOptions.Builder.disallowTruncate().followRedirects().validateCertificate().setDeadline(20.0));
    log.info("payload=" + ops);
    req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=UTF-8"));
    req.setPayload(ops.toString().getBytes(Charsets.UTF_8));
    System.out.println("req: " + ops.toString());
    JSONObject result = parseJsonResponseBody(fetch.fetch(req, robotErrorCode401Detector));
    log.info("result=" + ValueUtils.abbrev("" + result, 500));
    try {
        if (result.has("error")) {
            log.warning("Error result: " + result);
            JSONObject error = result.getJSONObject("error");
            throw new RuntimeException("Error from robot API: " + error);
        } else if (result.has("data")) {
            JSONObject data = result.getJSONObject("data");
            if (data.length() == 0) {
                // Apparently, the server often sends {"id":"op_id", "data":{}} when
                // something went wrong on the server side, so we translate that to an
                // IOException.
                throw new IOException("Robot API response looks like an error: " + result);
            } else {
                return data;
            }
        } else {
            throw new RuntimeException("Result has neither error nor data: " + result);
        }
    } catch (JSONException e) {
        throw new RuntimeException("JSONException parsing result: " + result, e);
    }
}

From source file:waveimport.RobotApi.java

private JSONObject callRobotApi1(String method, Map<String, Object> params) throws IOException {
    JSONArray ops = new JSONArray();
    try {/*w  w  w.j  av  a 2s.  c  om*/
        JSONObject jsonParams = new JSONObject();
        for (Map.Entry<String, Object> e : params.entrySet()) {
            jsonParams.put(e.getKey(), e.getValue());
        }
        JSONObject op = new JSONObject();
        op.put("params", jsonParams);
        op.put("method", method);
        op.put("id", OP_ID);
        ops.put(op);
    } catch (JSONException e) {
        throw new RuntimeException("Failed to construct JSON object", e);
    }
    HTTPRequest req = new HTTPRequest(new URL(baseUrl), HTTPMethod.POST,
            FetchOptions.Builder.disallowTruncate().followRedirects().validateCertificate().setDeadline(20.0));
    log.info("payload=" + ops);
    req.setHeader(new HTTPHeader("Content-Type", "application/json; charset=UTF-8"));
    req.setPayload(ops.toString().getBytes(Charsets.UTF_8));
    System.out.println("req: " + ops.toString());
    JSONObject result = parseJsonResponseBody(fetch.fetch(req, robotErrorCode401Detector));
    log.info("result=" + ValueUtils.abbrev("" + result, 500));
    return result;
}