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:eu.ttbox.androgister.sync.client.NetworkUtilities.java

/**
 * Perform 2-way sync with the server-side contacts. We send a request that
 * includes all the locally-dirty contacts so that the server can process
 * those changes, and we receive (and return) a list of contacts that were
 * updated on the server-side that need to be updated locally.
 *
 * @param account The account being synced
 * @param authtoken The authtoken stored in the AccountManager for this
 *            account//  w w w.  ja  va  2  s. c o  m
 * @param serverSyncState A token returned from the server on the last sync
 * @param dirtyContacts A list of the contacts to send to the server
 * @return A list of contacts that we need to update locally
 */
public static List<RawContact> syncContacts(Account account, String authtoken, long serverSyncState,
        List<RawContact> dirtyContacts)
        throws JSONException, ParseException, IOException, AuthenticationException {
    // Convert our list of User objects into a list of JSONObject
    List<JSONObject> jsonContacts = new ArrayList<JSONObject>();
    for (RawContact rawContact : dirtyContacts) {
        jsonContacts.add(rawContact.toJSONObject());
    }

    // Create a special JSONArray of our JSON contacts
    JSONArray buffer = new JSONArray(jsonContacts);

    // Create an array that will hold the server-side contacts
    // that have been changed (returned by the server).
    final ArrayList<RawContact> serverDirtyList = new ArrayList<RawContact>();

    // Prepare our POST data
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, account.name));
    params.add(new BasicNameValuePair(PARAM_AUTH_TOKEN, authtoken));
    params.add(new BasicNameValuePair(PARAM_CONTACTS_DATA, buffer.toString()));
    if (serverSyncState > 0) {
        params.add(new BasicNameValuePair(PARAM_SYNC_STATE, Long.toString(serverSyncState)));
    }
    Log.i(TAG, params.toString());
    HttpEntity entity = new UrlEncodedFormEntity(params);

    // Send the updated friends data to the server
    Log.i(TAG, "Syncing to: " + SYNC_CONTACTS_URI);
    final HttpPost post = new HttpPost(SYNC_CONTACTS_URI);
    post.addHeader(entity.getContentType());
    post.setEntity(entity);
    final HttpResponse resp = getHttpClient().execute(post);
    final String response = EntityUtils.toString(resp.getEntity());
    if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        // Our request to the server was successful - so we assume
        // that they accepted all the changes we sent up, and
        // that the response includes the contacts that we need
        // to update on our side...
        final JSONArray serverContacts = new JSONArray(response);
        Log.d(TAG, response);
        for (int i = 0; i < serverContacts.length(); i++) {
            RawContact rawContact = RawContact.valueOf(serverContacts.getJSONObject(i));
            if (rawContact != null) {
                serverDirtyList.add(rawContact);
            }
        }
    } else {
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
            Log.e(TAG, "Authentication exception in sending dirty contacts");
            throw new AuthenticationException();
        } else {
            Log.e(TAG, "Server error in sending dirty contacts: " + resp.getStatusLine());
            throw new IOException();
        }
    }

    return serverDirtyList;
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void updateNote(int row_id) {

    try {// w w  w. j a  v a2 s  . c  om
        JSONArray tagID = db.getSelectedTagId(selectedTags);
        long stage_id = Long.parseLong(stages.get(noteStages.getSelectedItem().toString()));
        ContentValues values = new ContentValues();
        JSONObject vals = new JSONObject();

        // If Pad Installed Over Server
        if (padAdded) {
            JSONArray url = new JSONArray();
            url.put(originalMemo);
            JSONObject obj = oe_obj.call_kw("pad.common", "pad_get_content", url);

            // HTMLHelper helper = new HTMLHelper();
            String link = HTMLHelper.htmlToString(obj.getString("result"));
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(link));
            vals.put("name", values.get("name").toString());

            values.put("memo", obj.getString("result"));
            vals.put("memo", values.get("memo").toString());

            values.put("note_pad_url", originalMemo);
            vals.put("note_pad_url", values.get("note_pad_url").toString());
        } // If Pad Not Installed Over Server
        else {
            values.put("stage_id", stage_id);
            vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString()));

            values.put("name", db.generateName(noteMemo.getText().toString()));
            vals.put("name", values.get("name").toString());

            values.put("memo", Html.toHtml(noteMemo.getText()));
            vals.put("memo", values.get("memo").toString());
        }

        JSONArray tag_ids = new JSONArray();
        tag_ids.put(6);
        tag_ids.put(false);
        JSONArray c_ids = new JSONArray(tagID.toString());
        tag_ids.put(c_ids);
        vals.put("tag_ids", new JSONArray("[" + tag_ids.toString() + "]"));

        // This will update Notes over Server And Local database
        db = new NoteDBHelper(scope.context());
        if (oe_obj.updateValues(db.getModelName(), vals, row_id)) {
            db.write(db, values, row_id, true);
            db.executeSQL("delete from note_note_note_tag_rel where note_note_id = ? and oea_name = ?",
                    new String[] { row_id + "", scope.User().getAndroidName() });
            for (int i = 0; i < tagID.length(); i++) {
                ContentValues rel_vals = new ContentValues();
                rel_vals.put("note_note_id", row_id);
                rel_vals.put("note_tag_id", tagID.getInt(i));
                rel_vals.put("oea_name", scope.User().getAndroidName());
                SQLiteDatabase insertDb = db.getWritableDatabase();
                insertDb.insert("note_note_note_tag_rel", null, rel_vals);
                insertDb.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:nz.co.wholemeal.christchurchmetro.FavouritesActivity.java

public static void saveFavourites(SharedPreferences favourites) {
    SharedPreferences.Editor editor = favourites.edit();
    JSONArray stopArray = new JSONArray();
    Iterator iterator = stops.iterator();
    while (iterator.hasNext()) {
        Stop stop = (Stop) iterator.next();
        stopArray.put(stop.platformTag);
    }//from w ww . ja v a  2s.  c om
    editor.putString("favouriteStops", stopArray.toString());
    Log.d(TAG, "Saving " + stops.size() + " favourites");
    Log.d(TAG, "json = " + stopArray.toString());
    editor.commit();
}

From source file:org.lisapark.octopus.util.json.JsonUtils.java

/**
 * //  w w w  .ja  v  a 2s.com
 * @param jsonRow
 * @param nodeName
 * @param jsonCells
 * @param stack
 * @return
 * @throws JSONException 
 */
private JSONObject buildNestedJsonObject(JSONObject jsonRow, String nodeName, JSONArray jsonCells,
        List<String> stack) throws JSONException {
    jsonRow = jsonRow.put(nodeName + "", jsonCells.toString());
    for (int i = stack.size(); i > 0; i--) {
        jsonRow = jsonRow.put(stack.get(i - 1), jsonRow.toString());
    }
    stack.add(nodeName);
    return jsonRow;
}

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

private void confirm_allvalues() throws JSONException {
    // TODO Auto-generated method stub

    /*String spinnertype1 = ((Spinner)findViewById(R.id.spinner_PurchaserType)).getSelectedItem().toString();
    String spinnertype2 = ((Spinner)findViewById(R.id.spinner_PurchaserType2)).getSelectedItem().toString();
    String spinnertype3 = ((Spinner)findViewById(R.id.spinner_PurchaserType3)).getSelectedItem().toString();
    String spinnertype4 = ((Spinner)findViewById(R.id.spinner_PurchaserType4)).getSelectedItem().toString();*/

    //   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\":\"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" + "\":" + "\"" + f_yes + "\",\"" + "PurlawyerRepresented" + "\":" + "\"" + l_yes + "\",\"" + "PurSPADate" + "\":" + "\"" + spa_date.getText().toString() + "\", \"" + "PurEntryOfPrivateCaveat" + "\":" + "\"" + entry_private_caveat.getText().toString() + "\", \"" + "PurWithOfPrivateCaveat" + "\":" + "\"" + withdrawal_private_caveat.getText().toString() + "\" ,\"" + "PurFirstName" + "\":" + "\"" + name1.getText().toString() + "\",\"" + "PurFirstID" + "\":" + "\"" + brn_no1.getText().toString() + "\",\"" + "PurFirstTaxNo" + "\":" + "\"" + tax_no1.getText().toString() + "\",\"" + "PurFirstContactNo" + "\":" + "\"" + contact_no1.getText().toString() + "\",\"" + "PurFirstType" + "\":" + "\"" + spinnertype1 + "\",\"" + "PurSecName" + "\":" + "\"" + name2.getText().toString() + "\",\"" + "PurSecID" + "\":" + "\"" + brn_no2.getText().toString() + "\",\"" + "PurSecTaxNo" + "\":" + "\"" + tax_no2.getText().toString() + "\",\"" + "PurSecContactNo" + "\":" + "\"" + contact_no2.getText().toString() + "\",\"" + "PurSecType" + "\":" + "\"" + spinnertype2 + "\",\"" + "PurThirdName" + "\":" + "\"" + name3.getText().toString() + "\",\"" + "PurThirdID" + "\":" + "\"" + brn_no3.getText().toString() + "\",\"" + "PurThirdTaxNo" + "\":" + "\"" + tax_no3.getText().toString() + "\",\"" + "PurThirdContactNo" + "\":" + "\"" + contact_no3.getText().toString() + "\",\"" + "PurThirdType" + "\":" + "\"" + spinnertype3 + "\",\"" + "PurFourthName" + "\":" + "\"" + name4.getText().toString() + "\",\"" + "PurFourthID" + "\":" + "\"" + brn_no4.getText().toString() + "\",\"" + "PurFourthTaxNo" + "\":" + "\"" + tax_no4.getText().toString() + "\",\"" + "PurFourthContactNo" + "\":" + "\"" + contact_no4.getText().toString() + "\",\"" + "PurFourthType" + "\":" + "\"" + spinnertype4 + "\"},\"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/201512: 00: 00AM\", \"CaseFileNo\": \"JJ/1500000001/\", \"KIV\": \"\", \"TabId\": \"6\", \"Details\": {}, \"Purchaser\": {}, \"Vendor\": {}, \"Property\": {}, \"LoanPrinciple\": {}, \"LoanSubsidary\": { \"LoanDocForBankExe\":\""
            + ELoanDocForBankExe.getText().toString() + "\", \"FaciAgreeDate\":\""
            + EFaciAgreeDate.getText().toString() + "\", \"LoanDocRetFromBank\":\""
            + EeditText_loan_doc_bank.getText().toString() + "\", \"DischargeofCharge\":\""
            + EeditText_dischargeofcharge.getText().toString() + "\", \"FirstTypeofFacility\":\"" + f1Value
            + "\", \"FirstFacilityAmt\":\"" + EeditText_fac_amount.getText().toString()
            + "\", \"FirstRepaymt\":\"" + EeditText_repayment.getText().toString()
            + "\", \"FirstIntrstRate\":\"" + EeditText_interestrate.getText().toString()
            + "\", \"FirstMonthlyInstmt\":\"" + EeditText_monthly_installment.getText().toString()
            + "\", \"FirstTermLoanAmt\":\"" + EeditText_loan_amt.getText().toString()
            + "\", \"FirstInterest\":\"" + EeditText_interest.getText().toString() + "\", \"FirstODLoan\":\""
            + EeditText_od_loan.getText().toString() + "\", \"FirstMRTA\":\""
            + EeditText_mrta.getText().toString() + "\", \"FirstBankGuarantee\":\""
            + EeditText_bank_guarantee.getText().toString() + "\", \"FirstLetterofCredit\":\""
            + EeditText_letterofcredit.getText().toString() + "\", \"FirstTrustReceipt\":\""
            + EeditText_trust_receipt.getText().toString() + "\", \"FirstOthers\":\""
            + EeditText_others.getText().toString() + "\", \"SecTypeofFacility\":\"" + f2Value
            + "\", \"SecFacilityAmt\":\"" + EeditText_fac_amount1.getText().toString() + "\", \"SecRepaymt\":\""
            + EeditText_repayment1.getText().toString() + "\", \"SecIntrstRate\":\""
            + EeditText_interestrate1.getText().toString() + "\", \"SecMonthlyInstmt\":\""
            + EeditText_monthly_installment1.getText().toString() + "\", \"SecTermLoanAmt\":\""
            + EeditText_loan_amt1.getText().toString() + "\", \"SecInterest\":\""
            + EeditText_interest1.getText().toString() + "\", \"SecODLoan\":\""
            + EeditText_od_loan1.getText().toString() + "\", \"SecMRTA\":\""
            + EeditText_mrta1.getText().toString() + "\", \"SecBankGuarantee\":\""
            + EeditText_bank_guarantee1.getText().toString() + "\", \"SecLetterofCredit\":\""
            + EeditText_letterofcredit1.getText().toString() + "\", \"SecTrustReceipt\":\""
            + EeditText_trust_receipt1.getText().toString() + "\", \"SecOthers\":\""
            + EeditText_others1.getText().toString() + "\", \"ThirdTypeofFacility\":\"" + f3Value
            + "\", \"ThirdFacilityAmt\":\"" + EeditText_fac_amount2.getText().toString()
            + "\", \"ThirdRepaymt\":\"" + EeditText_repayment2.getText().toString()
            + "\", \"ThirdIntrstRate\":\"" + EeditText_interestrate2.getText().toString()
            + "\", \"ThirdMonthlyInstmt\":\"" + EeditText_monthly_installment2.getText().toString()
            + "\", \"ThirdTermLoanAmt\":\"" + EeditText_loan_amt2.getText().toString()
            + "\", \"ThirdInterest\":\"" + EeditText_interest2.getText().toString() + "\", \"ThirdODLoan\":\""
            + EeditText_od_loan2.getText().toString() + "\", \"ThirdMRTA\":\""
            + EeditText_mrta2.getText().toString() + "\", \"ThirdBankGuarantee\":\""
            + EeditText_bank_guarantee2.getText().toString() + "\", \"ThirdLetterofCredit\":\""
            + EeditText_letterofcredit2.getText().toString() + "\", \"ThirdTrustReceipt\":\""
            + EeditText_trust_receipt2.getText().toString() + "\", \"ThirdOthers\":\""
            + EeditText_others2.getText().toString() + "\", \"FourthTypeofFacility\":\"" + f4Value
            + "\", \"FourthFacilityAmt\":\"" + EeditText_fac_amount3.getText().toString()
            + "\", \"FourthRepaymt\":\"" + EeditText_repayment3.getText().toString()
            + "\", \"FourthIntrstRate\":\"" + EeditText_interestrate3.getText().toString()
            + "\", \"FourthMonthlyInstmt\":\"" + EeditText_monthly_installment3.getText().toString()
            + "\", \"FourthTermLoanAmt\":\"" + EeditText_loan_amt3.getText().toString()
            + "\", \"FourthInterest\":\"" + EeditText_interest3.getText().toString() + "\", \"FourthODLoan\":\""
            + EeditText_od_loan3.getText().toString() + "\", \"FourthMRTA\":\""
            + EeditText_mrta3.getText().toString() + "\", \"FourthBankGuarantee\":\""
            + EeditText_bank_guarantee3.getText().toString() + "\", \"FourthLetterofCredit\":\""
            + EeditText_letterofcredit3.getText().toString() + "\", \"FourthTrustReceipt\":\""
            + EeditText_trust_receipt3.getText().toString() + "\", \"FourthOthers\":\""
            + EeditText_others3.getText().toString() + "\", \"FifthTypeofFacility\":\"" + f5Value
            + "\", \"FifthFacilityAmt\":\"" + EeditText_fac_amount4.getText().toString()
            + "\", \"FifthRepaymt\":\"" + EeditText_repayment4.getText().toString()
            + "\", \"FifthIntrstRate\":\"" + EeditText_interestrate4.getText().toString()
            + "\", \"FifthMonthlyInstmt\":\"" + EeditText_monthly_installment4.getText().toString()
            + "\", \"FifthTermLoanAmt\":\"" + EeditText_loan_amt4.getText().toString()
            + "\", \"FifthInterest\":\"" + EeditText_interest4.getText().toString() + "\", \"FifthODLoan\":\""
            + EeditText_od_loan4.getText().toString() + "\", \"FifthMRTA\":\""
            + EeditText_mrta4.getText().toString() + "\", \"FifthBankGuarantee\":\""
            + EeditText_bank_guarantee4.getText().toString() + "\", \"FifthLetterofCredit\":\""
            + EeditText_letterofcredit4.getText().toString() + "\", \"FifthTrustReceipt\":\""
            + EeditText_trust_receipt4.getText().toString() + "\", \"FifthOthers\":\""
            + EeditText_others4.getText().toString() + "\" } } ]";

    Log.e("pur_string", json_element);

    JSONObject valuesObject = null;/*from   ww  w  . ja  v a  2  s .c  o 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();
    }

    Log.v("texttt", list.toString());

    RequestParams params = new RequestParams();
    params.put("sJsonInput", list.toString());
    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(ProcesscaseLoanSubsidiary.this, ProcessCaseProcessTab.class);
                startActivity(iAddBack);
                Toast.makeText(ProcesscaseLoanSubsidiary.this, messageDisplay, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(ProcesscaseLoanSubsidiary.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.groupon.odo.proxylib.BackupService.java

/**
 * 1. Resets profile to get fresh slate//from w ww.j  a  v  a2s.  c om
 * 2. Updates active server group to one from json
 * 3. For each path in json, sets request/response enabled
 * 4. Adds active overrides to each path
 * 5. Update arguments and repeat count for each override
 *
 * @param profileBackup JSON containing server configuration and overrides to activate
 * @param profileId Profile to update
 * @param clientUUID Client UUID to apply update to
 * @return
 * @throws Exception Array of errors for things that could not be imported
 */
public void setProfileFromBackup(JSONObject profileBackup, int profileId, String clientUUID) throws Exception {
    // Reset the profile before applying changes
    ClientService clientService = ClientService.getInstance();
    clientService.reset(profileId, clientUUID);
    clientService.updateActive(profileId, clientUUID, true);
    JSONArray errors = new JSONArray();

    // Change to correct server group
    JSONObject activeServerGroup = profileBackup.getJSONObject(Constants.BACKUP_ACTIVE_SERVER_GROUP);
    int activeServerId = getServerIdFromName(activeServerGroup.getString(Constants.NAME), profileId);
    if (activeServerId == -1) {
        errors.put(formErrorJson("Server Error", "Cannot change to '"
                + activeServerGroup.getString(Constants.NAME) + "' - Check Server Group Exists"));
    } else {
        Client clientToUpdate = ClientService.getInstance().findClient(clientUUID, profileId);
        ServerRedirectService.getInstance().activateServerGroup(activeServerId, clientToUpdate.getId());
    }

    JSONArray enabledPaths = profileBackup.getJSONArray(Constants.ENABLED_PATHS);
    PathOverrideService pathOverrideService = PathOverrideService.getInstance();
    OverrideService overrideService = OverrideService.getInstance();

    for (int i = 0; i < enabledPaths.length(); i++) {
        JSONObject path = enabledPaths.getJSONObject(i);
        int pathId = pathOverrideService.getPathId(path.getString(Constants.PATH_NAME), profileId);
        // Set path to have request/response enabled as necessary
        try {
            if (path.getBoolean(Constants.REQUEST_ENABLED)) {
                pathOverrideService.setRequestEnabled(pathId, true, clientUUID);
            }

            if (path.getBoolean(Constants.RESPONSE_ENABLED)) {
                pathOverrideService.setResponseEnabled(pathId, true, clientUUID);
            }
        } catch (Exception e) {
            errors.put(formErrorJson("Path Error",
                    "Cannot update path: '" + path.getString(Constants.PATH_NAME) + "' - Check Path Exists"));
            continue;
        }

        JSONArray enabledOverrides = path.getJSONArray(Constants.ENABLED_ENDPOINTS);

        /**
         * 2 for loops to ensure overrides are added with correct priority
         * 1st loop is priority currently adding override to
         * 2nd loop is to find the override with matching priority in profile json
         */
        for (int j = 0; j < enabledOverrides.length(); j++) {
            for (int k = 0; k < enabledOverrides.length(); k++) {
                JSONObject override = enabledOverrides.getJSONObject(k);
                if (override.getInt(Constants.PRIORITY) != j) {
                    continue;
                }

                int overrideId;
                // Name of method that can be used by error message as necessary later
                String overrideNameForError = "";
                // Get the Id of the override
                try {
                    // If method information is null, then the override is a default override
                    if (override.get(Constants.METHOD_INFORMATION) != JSONObject.NULL) {
                        JSONObject methodInformation = override.getJSONObject(Constants.METHOD_INFORMATION);
                        overrideNameForError = methodInformation.getString(Constants.METHOD_NAME);
                        overrideId = overrideService.getOverrideIdForMethod(
                                methodInformation.getString(Constants.CLASS_NAME),
                                methodInformation.getString(Constants.METHOD_NAME));
                    } else {
                        overrideNameForError = "Default Override";
                        overrideId = override.getInt(Constants.OVERRIDE_ID);
                    }

                    // Enable override and set repeat number and arguments
                    overrideService.enableOverride(overrideId, pathId, clientUUID);
                    overrideService.updateRepeatNumber(overrideId, pathId, override.getInt(Constants.PRIORITY),
                            override.getInt(Constants.REPEAT_NUMBER), clientUUID);
                    overrideService.updateArguments(overrideId, pathId, override.getInt(Constants.PRIORITY),
                            override.getString(Constants.ARGUMENTS), clientUUID);
                } catch (Exception e) {
                    errors.put(formErrorJson("Override Error", "Cannot add/update override: '"
                            + overrideNameForError + "' - Check Override Exists"));
                    continue;
                }
            }
        }
    }

    // Throw exception if any errors occured
    if (errors.length() > 0) {
        throw new Exception(errors.toString());
    }
}

From source file:org.eclipse.orion.server.authentication.formopenid.ManageOpenidsServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    String pathInfo = req.getPathInfo() == null ? "" : req.getPathInfo(); //$NON-NLS-1$
    try {// w  w w. j  av a2 s  .  co m
        if (pathInfo.startsWith("/openid")) { //$NON-NLS-1$
            String openid = req.getParameter(OpenIdHelper.OPENID);
            if (openid != null) {
                consumer = OpenIdHelper.redirectToOpenIdProvider(req, response, consumer);
                return;
            }

            String op_return = req.getParameter(OpenIdHelper.OP_RETURN);
            if (op_return != null) {
                OpenIdHelper.handleOpenIdReturn(req, response, consumer);
                return;
            }
        }
    } catch (OpenIdException e) {
        writeOpenIdError(e.getMessage(), req, response);
        return;
    }

    JSONArray providersJson = new JSONArray();
    for (OpendIdProviderDescription provider : getSupportedOpenids(req)) {
        JSONObject providerJson = new JSONObject();
        try {
            providerJson.put(ProtocolConstants.KEY_NAME, provider.getName());
            providerJson.put(OpenIdConstants.KEY_IMAGE, provider.getImage());
            providerJson.put(OpenIdConstants.KEY_URL, provider.getAuthSite());
            providersJson.put(providerJson);
        } catch (JSONException e) {
            LogHelper.log(new Status(IStatus.ERROR, Activator.PI_AUTHENTICATION_SERVLETS,
                    "Exception writing OpenId provider " + provider.getName(), e)); //$NON-NLS-1$
        }
    }

    response.setContentType("application/json"); //$NON-NLS-1$
    PrintWriter writer = response.getWriter();
    writer.append(providersJson.toString());
    writer.flush();
}

From source file:com.camnter.savevolley.hurl.toolbox.JsonArrayRequest.java

/**
 * Creates a new request.// w ww.  j  a  v a  2 s.co  m
 *
 * @param method the HTTP method to use
 * @param url URL to fetch the JSON from
 * @param jsonRequest A {@link JSONArray} to post with the request. Null is allowed and
 * indicates no parameters will be posted along with request.
 * @param listener Listener to receive the JSON response
 * @param errorListener Error listener, or null to ignore errors.
 */
public JsonArrayRequest(int method, String url, JSONArray jsonRequest, Listener<JSONArray> listener,
        ErrorListener errorListener) {
    super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, errorListener);
}

From source file:com.smile.moment.ui.activity.NightChatActivity.java

private void getBooks(final LoadingView loadingView, final boolean isLoad, final String url,
        final String docsId) {
    if (!NetWorkUtil.isNetworkAvailable(context)) {
        ToastUtil.showSortToast(context, "?");
        refreshLayout.setRefreshing(false);
        if (loadingView != null)
            loadingView.setLoadError();// w ww . ja v  a  2 s.co m
        return;
    }
    VolleyHttpClient.getInstance(context).get(url, null, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try {
                if (!isLoad) {
                    list.clear();
                }
                refreshLayout.setRefreshing(false);
                JSONObject jsonObject = new JSONObject(response);
                JSONObject data = jsonObject.getJSONObject(docsId);
                JSONArray topics = data.getJSONArray("topics");
                JSONObject topic = topics.getJSONObject(0);
                JSONArray docs = topic.getJSONArray("docs");
                String book = docs.toString();
                List<Image> imageList = new Gson().fromJson(book, new TypeToken<List<Image>>() {
                }.getType());
                if (imageList.size() == 0) {
                    if (loadingView != null)
                        loadingView.setNoData();
                }
                Image image = new Image();
                image.setType(Image.TYPE_BANNER);
                image.setImgsrc(data.getString("banner"));
                list.add(image);
                list.addAll(imageList);
                adapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (loadingView != null)
                loadingView.setLoadError();
            refreshLayout.setRefreshing(false);
        }
    });
}

From source file:cc.redpen.formatter.JSONFormatter.java

@Override
public void format(PrintWriter pw, Map<Document, List<ValidationError>> docErrorsMap)
        throws RedPenException, IOException {
    BufferedWriter writer = new BufferedWriter(new PrintWriter(pw));
    JSONArray errors = new JSONArray();
    docErrorsMap.forEach((doc, errorList) -> errors.put(asJSON(doc, errorList)));
    writer.write(errors.toString());
    writer.flush();/*from  ww w.j  a v a2s  .com*/
}