List of usage examples for org.json JSONObject put
public JSONObject put(String key, Object value) throws JSONException
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
private void btnconfirm() { // Find the SharedPreferences pass Login value SharedPreferences prefLoginReturn = getSharedPreferences("LoginData", Context.MODE_PRIVATE); System.out.println("LOGIN DATA"); String userName = prefLoginReturn.getString("sUserName", ""); String category = prefLoginReturn.getString("sCategory", ""); System.out.println(category); String CardCode = prefLoginReturn.getString("CardCode", ""); System.out.println(CardCode); JSONObject jsonObject = new JSONObject(); // jsonObject.put("Category", "SPA"); try {/*from w ww .jav a 2 s .c o m*/ // Find confirmation message // messageResult = jsonObject.getString("Result").toString(); jsonObject.put("CODE", ""); jsonObject.put("CARDCODE", CardCode); jsonObject.put("TITLETYPE", titleValue); jsonObject.put("TITLENO", Title.getText().toString()); jsonObject.put("LOTTYPE", LotType.getText().toString()); jsonObject.put("LOTNO", LotNo.getText().toString()); jsonObject.put("FORMERLY_KNOWN_AS", Knownas.getText().toString()); jsonObject.put("BPM", Pekan.getText().toString()); jsonObject.put("STATE", stateval); jsonObject.put("AREA", Nageri.getText().toString()); jsonObject.put("LOTAREA", LotArea.getText().toString()); jsonObject.put("LASTUPDATEDON", LastUpdate.getText().toString()); jsonObject.put("DEVELOPER", developerValue); jsonObject.put("DVLPR_CODE", developerValue_id); jsonObject.put("PROJECT_CODE", ProjectValue_id); jsonObject.put("PROJECTNAME", ProjectValue); jsonObject.put("DEVLICNO", DevLicense.getText().toString()); jsonObject.put("DEVSOLICTOR", solicitorValue); jsonObject.put("DVLPR_SOL_CODE", solicitorValue_id); jsonObject.put("DVLPR_LOC", SolicitorLoc.getText().toString()); jsonObject.put("LSTCHG_BANKCODE", bankValue_id); jsonObject.put("LSTCHG_BANKNAME", bankValue); jsonObject.put("LSTCHG_BRANCH", Branch.getText().toString()); jsonObject.put("LSTCHG_PANO", PAName.getText().toString()); jsonObject.put("LSTCHG_PRSTNO", PresentaionNo.getText().toString()); jsonObject.put("PurchasePrice", PurchasePrice.getText().toString()); if (QryGroup13.isChecked()) jsonObject.put("PROPERTYCHARGED", "Y"); else jsonObject.put("PROPERTYCHARGED", "N"); //arrOfJson.put(jsonObject); System.out.println("JsonArray:" + jsonObject.toString()); //upDateList(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } RequestParams params = new RequestParams(); params.put("sJsonInput", jsonObject.toString()); System.out.println("params"); System.out.println(params); dialog = ProgressDialog.show(AddCaseStep2of4.this, "", "Loading...", true); RestService.post(METHOD_ADD_CASE2, 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"); dialog.dismiss(); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("onFailure"); System.out.println("AddCase2 Details Add Confirmed"); System.out.println(arg2); dialog.dismiss(); // Find status Response try { StatusResult = jsonResponse.getString("Result").toString(); messageDisplay = jsonResponse.getString("DisplayMessage").toString(); if (StatusResult.equals("SUCCESS")) { Intent iAddBack = new Intent(AddCaseStep2of4.this, AddCaseStep3of4.class); startActivity(iAddBack); Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show(); } else if (jsonResponse.getString("CaseFileNo").toString() != "") { // Find Response for ListView try { jsonCaselist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); /* * [ { "CaseFileNo": "1500000006", "RelatedFileNo": * "", "BranchCode": "", "FileOpenedDate": * "8/1/2015 12:00:00 AM", "IC": "3", "CaseType": * "SPA", "ClientName": "", "BankName": "", * "Branch": "", "LOTNo": "", "CaseAmount": "", * "UserCode": "", "Status": "OPEN", * "FileClosedDate": "" } ] */ CaseList_CaseFileNo = jsonResponse.getString("CaseFileNo").toString(); CaseList_RelatedFileNo = jsonResponse.getString("RelatedFileNo").toString(); CaseList_BranchCode = jsonResponse.getString("BranchCode").toString(); CaseList_FileOpenedDate = jsonResponse.getString("FileOpenedDate").toString(); CaseList_IC = jsonResponse.getString("IC").toString(); CaseList_CaseType = jsonResponse.getString("CaseType").toString(); CaseList_ClientName = jsonResponse.getString("ClientName").toString(); CaseList_BankName = jsonResponse.getString("BankName").toString(); // CaseList_Branch = // jsonResponse.getString("Branch").toString(); CaseList_LOTNo = jsonResponse.getString("LOTNo").toString(); CaseList_CaseAmount = jsonResponse.getString("CaseAmount").toString(); CaseList_UserCode = jsonResponse.getString("UserCode").toString(); CaseList_Status = jsonResponse.getString("Status").toString(); CaseList_FileClosedDate = jsonResponse.getString("FileClosedDate").toString(); // SEND JSON DATA INTO CASELIST HashMap<String, String> caseListProperty = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON CASE LIST"); caseListProperty.put("CaseFileNo_List", CaseList_CaseFileNo); System.out.println(CaseList_CaseFileNo); caseListProperty.put("RelatedFileNo_List", CaseList_RelatedFileNo); System.out.println(CaseList_RelatedFileNo); caseListProperty.put("BranchCode_List", CaseList_BranchCode); System.out.println(CaseList_BranchCode); caseListProperty.put("FileOpenedDate_List", CaseList_FileOpenedDate); System.out.println(CaseList_FileOpenedDate); caseListProperty.put("IC_List", CaseList_IC); System.out.println(CaseList_IC); caseListProperty.put("CaseType_List", CaseList_CaseType); System.out.println(CaseList_CaseType); caseListProperty.put("ClientName_List", CaseList_ClientName); System.out.println(CaseList_ClientName); caseListProperty.put("BankName_List", CaseList_BankName); System.out.println(CaseList_BankName); // caseListProperty.put("Branch_List",CaseList_Branch); // System.out.println(CaseList_Branch); caseListProperty.put("LOTNo_List", CaseList_LOTNo); System.out.println(CaseList_LOTNo); caseListProperty.put("CaseAmount_List", CaseList_CaseAmount); System.out.println(CaseList_CaseAmount); caseListProperty.put("UserCode_List", CaseList_UserCode); System.out.println(CaseList_UserCode); caseListProperty.put("Status_List", CaseList_Status); System.out.println(CaseList_Status); caseListProperty.put("FileClosedDate", CaseList_FileClosedDate); System.out.println(CaseList_FileClosedDate); System.out.println(" END SEND JSON CASE LIST"); jsonCaselist.add(caseListProperty); System.out.println("JSON CASELIST"); System.out.println(jsonCaselist); } } catch (JSONException e) { // TODO Auto-generated catc // block e.printStackTrace(); } //Toast.makeText(PropertyActivity.this, "Case Item Found", Toast.LENGTH_SHORT).show(); Intent intentList = new Intent(AddCaseStep2of4.this, PropertyRelatedCaseListActivity.class); intentList.putExtra("ProjectJsonList", jsonCaselist); startActivity(intentList); System.out.println(arg2); } else { Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Addcase3 Details Add Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownTitle() throws JSONException { RequestParams params = null;/*from w ww . ja va2 s . com*/ params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "@AE_PROPERTY"); jsonObject.put("FieldName", "TITLETYPE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(TitleType_DROPDOWN, 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("Failed"); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("property Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonlistProject = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonlistProject.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonlistProject); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(AddCaseStep2of4.this, jsonlistProject, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertyTitleType.setAdapter(sAdapPROJ); /*for (int j = 0; j < jsonlistProject.size(); j++) { if (jsonlistProject.get(j).get("Id_T").equals(projectDetailResponse)) { TitleType_DROPDOWN.setSelection(j); break; } }*/ } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Property Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownState() throws JSONException { RequestParams params = null;/*w w w.j ava 2 s . co m*/ params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "STATE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(METHOD_PROPERTY_STATE, 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); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("State Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonliststate = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonliststate.add(proList); System.out.println("JSON STATE LIST"); System.out.println(jsonliststate); } // Spinner set Array Data in Drop down sAdaparea = new SimpleAdapter(AddCaseStep2of4.this, jsonliststate, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertySTATE.setAdapter(sAdaparea); for (int j = 0; j < jsonliststate.size(); j++) { if (jsonliststate.get(j).get("Id_T").equals(statevalue)) { spinnerpropertySTATE.setSelection(j); break; } } } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("State Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.example.android.samplesync.client.RawContact.java
/** * Convert the RawContact object into a JSON string. From the * JSONString interface./*from w w w . j a v a2s . c o m*/ * @return a JSON string representation of the object */ public JSONObject toJSONObject() { JSONObject json = new JSONObject(); try { if (!TextUtils.isEmpty(mFirstName)) { json.put("f", mFirstName); } if (!TextUtils.isEmpty(mLastName)) { json.put("l", mLastName); } if (!TextUtils.isEmpty(mCellPhone)) { json.put("m", mCellPhone); } if (!TextUtils.isEmpty(mOfficePhone)) { json.put("o", mOfficePhone); } if (!TextUtils.isEmpty(mHomePhone)) { json.put("h", mHomePhone); } if (!TextUtils.isEmpty(mEmail)) { json.put("e", mEmail); } if (mServerContactId > 0) { json.put("i", mServerContactId); } if (mRawContactId > 0) { json.put("c", mRawContactId); } if (mDeleted) { json.put("d", mDeleted); } } catch (final Exception ex) { Log.i(TAG, "Error converting RawContact to JSONObject" + ex.toString()); } return json; }
From source file:com.wso2.mobile.mdm.api.PhoneState.java
/** * Generate Data Usage Report//ww w. java 2 s . c o m */ public JSONObject takeDataUsageSnapShot() { previous = latest; latest = new TrafficSnapshot(context); JSONObject dataObj = new JSONObject(); JSONArray jsonArray = new JSONArray(); String latestRX, latestTX, previousRX, previousTX, deltaRX, deltaTX; latestRX = String.valueOf(formatSizeMB(latest.device.rx)); latestTX = String.valueOf(formatSizeMB(latest.device.tx)); try { dataObj.put("totalupload", latestRX); dataObj.put("totaldownload", latestTX); if (previous != null) { previousRX = String.valueOf(previous.device.rx); previousTX = String.valueOf(previous.device.tx); deltaRX = String.valueOf(latest.device.rx - previous.device.rx); deltaTX = String.valueOf(latest.device.tx - previous.device.tx); } ArrayList<String> log = new ArrayList<String>(); HashSet<Integer> intersection = new HashSet<Integer>(latest.apps.keySet()); if (previous != null) { intersection.retainAll(previous.apps.keySet()); } for (Integer uid : intersection) { TrafficRecord latest_rec = latest.apps.get(uid); TrafficRecord previous_rec = (previous == null ? null : previous.apps.get(uid)); jsonArray.add(getDataUseReport(latest_rec.tag, latest_rec, previous_rec, log)); } dataObj.put("appdata", jsonArray); Collections.sort(log); for (String row : log) { Log.d("TrafficMonitor", row); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataObj; }
From source file:com.wso2.mobile.mdm.api.PhoneState.java
private JSONObject getDataUseReport(CharSequence name, TrafficRecord latest_rec, TrafficRecord previous_rec, ArrayList<String> rows) { JSONObject jsonObj = new JSONObject(); if (latest_rec.rx > -1 || latest_rec.tx > -1) { StringBuilder buf = new StringBuilder(name); try {/*from w w w . jav a2 s .c o m*/ jsonObj.put("package", name); jsonObj.put("name", appList.getAppNameFromPackage(name.toString())); jsonObj.put("upload", formatSizeMB(latest_rec.tx)); jsonObj.put("download", formatSizeMB(latest_rec.rx)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } buf.append("="); buf.append(String.valueOf(latest_rec.rx)); buf.append(" received"); if (previous_rec != null) { buf.append(" (delta="); buf.append(String.valueOf(latest_rec.rx - previous_rec.rx)); buf.append(")"); } buf.append(", "); buf.append(String.valueOf(latest_rec.tx)); buf.append(" sent"); if (previous_rec != null) { buf.append(" (delta="); buf.append(String.valueOf(latest_rec.tx - previous_rec.tx)); buf.append(")"); } rows.add(buf.toString()); } return jsonObj; }
From source file:com.soomla.store.domain.VirtualCategory.java
/** * Converts the current {@link VirtualCategory} to a JSONObject. * @return a JSONObject representation of the current {@link VirtualCategory}. *//*from w w w . j a v a 2 s . c o m*/ public JSONObject toJSONObject() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put(JSONConsts.CATEGORY_NAME, mName); JSONArray goodsArr = new JSONArray(); for (String goodItemId : mGoodsItemIds) { goodsArr.put(goodItemId); } jsonObject.put(JSONConsts.CATEGORY_GOODSITEMIDS, goodsArr); } catch (JSONException e) { StoreUtils.LogError(TAG, "An error occurred while generating JSON object."); } return jsonObject; }
From source file:biz.mosil.webtools.MosilWeb.java
/** * ? JsonString ?//from ww w .j a va 2 s. com * @return (String) <b>JsonString</b> Format: {"key1":"value1", "key2":"value2", ...} * */ public static final String parseToJsonString(Map<String, Object> _data) { String jsonString = ""; if (_data != null) { JSONObject json = new JSONObject(); try { for (Map.Entry<String, Object> data : _data.entrySet()) { json.put(data.getKey(), data.getValue()); } } catch (JSONException _ex) { Log.e(TAG, "Parse To JsonString Error: " + _ex.toString()); } jsonString = json.toString(); } return jsonString; }
From source file:com.basetechnology.s0.agentserver.script.runtime.ExceptionInfo.java
public JSONObject toJson() throws JSONException { JSONObject exceptionJson = new JsonListMap(); exceptionJson.put("type", type); exceptionJson.put("time", DateUtils.toRfcString(time)); exceptionJson.put("message", message); exceptionJson.put("script", scriptName); return exceptionJson; }
From source file:wsclient.Hitagi.java
public void auth(String login, String pass) { JSONObject json = new JSONObject(); json.put("type", "auth"); json.put("login", login); json.put("pass", pass); json.put("mobile", false); json.put("client", "Java Client"); client.sendMessage(json);/* w w w.ja v a2 s . c om*/ }