List of usage examples for org.json JSONArray JSONArray
public JSONArray(Object array) throws JSONException
From source file:fiskinfoo.no.sintef.fiskinfoo.MapFragment.java
private void createMapLayerSelectionDialog() { if (layersAndVisibility == null) { getLayersAndVisibility();/* w w w. ja va2 s. co m*/ } final Dialog dialog = dialogInterface.getDialog(getActivity(), R.layout.dialog_select_map_layers, R.string.choose_map_layers); Button okButton = (Button) dialog.findViewById(R.id.select_map_layers_update_map_button); final List<CheckBoxRow> rows = new ArrayList<>(); final LinearLayout mapLayerLayout = (LinearLayout) dialog.findViewById(R.id.map_layers_checkbox_layout); final Button cancelButton = (Button) dialog.findViewById(R.id.select_map_layers_cancel_button); LayerAndVisibility[] layers = new Gson().fromJson(layersAndVisibility.toString(), LayerAndVisibility[].class); for (LayerAndVisibility layer : layers) { if (layer.name.equals("Grunnkart") || layer.name.contains("OpenLayers_Control")) { continue; } boolean isActive; isActive = layer.isVisible; CheckBoxRow row = rowsInterface.getCheckBoxRow(getActivity(), layer.name, false, isActive); rows.add(row); View mapLayerRow = row.getView(); mapLayerLayout.addView(mapLayerRow); } okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List<String> layersList = new ArrayList<>(); layersList.add("Grunnkart"); for (int i = 0; i < mapLayerLayout.getChildCount(); i++) { if (rows.get(i).isChecked()) { layersList.add(rows.get(i).getText()); } } user.setActiveLayers(layersList); user.writeToSharedPref(getActivity()); dialog.dismiss(); if (layersList.contains(getString(R.string.fishing_facility_name)) && !user.getIsFishingFacilityAuthenticated()) { dialogInterface.getHyperlinkAlertDialog(getActivity(), getString(R.string.about_fishing_facility_title), getString(R.string.about_fishing_facility_details)).show(); } JSONArray json = new JSONArray(layersList); browser.loadUrl("javascript:toggleLayers(" + json + ")"); getLayersAndVisibility(); } }); cancelButton.setOnClickListener(onClickListenerInterface.getDismissDialogListener(dialog)); dialog.show(); }
From source file:com.atinternet.tracker.Tool.java
/** * Convert String to JSON//from w w w. j a v a2 s . co m * * @param s String * @return Object */ static Object parseJSON(String s) { try { return new JSONObject(s); } catch (JSONException e) { try { return new JSONArray(s); } catch (JSONException e1) { return null; } } }
From source file:com.bindez.nlp.converter.RabbitConverter.java
public static String replace_with_rule(String rule, String output) { try {/* w w w.j a v a 2 s . c o m*/ JSONArray rule_array = new JSONArray(rule); int max_loop = rule_array.length(); //because of JDK 7 bugs in Android output = output.replace("null", "\uFFFF\uFFFF"); for (int i = 0; i < max_loop; i++) { JSONObject obj = rule_array.getJSONObject(i); String from = obj.getString("from"); String to = obj.getString("to"); output = output.replaceAll(from, to); output = output.replace("null", ""); } } catch (JSONException e) { e.printStackTrace(); } output = output.replace("\uFFFF\uFFFF", "null"); return output; }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
@Override public void setJSONString(String jsonString) throws JSONException { clear();/*from www .j a v a 2 s . c o m*/ JSONObject jsonObject = new JSONObject(jsonString); Iterator<String> keySet = jsonObject.keys(); while (keySet.hasNext()) { String key = keySet.next(); String value = jsonObject.optString(key); JSONArray values = new JSONArray(value); for (int i = 0; i < values.length(); i++) add(key, values.optString(i)); } }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
@Override public final String toJSONString() { JSONObject jsonObject = new JSONObject(); Set<Map.Entry<String, List<String>>> entrySet = entrySet(); for (Map.Entry<String, List<String>> entry : entrySet) { String key = entry.getKey(); List<String> values = entry.getValue(); JSONArray value = new JSONArray(values); try {/*from w ww . ja va2 s .c o m*/ jsonObject.put(key, value); } catch (JSONException e) { Logger.w(e); } } return jsonObject.toString(); }
From source file:net.zorgblub.typhon.dto.PageOffsets.java
public String toJSON() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put(Fields.fontFamily.name(), this.fontFamily); jsonObject.put(Fields.fontSize.name(), this.fontSize); jsonObject.put(Fields.vMargin.name(), this.vMargin); jsonObject.put(Fields.hMargin.name(), this.hMargin); jsonObject.put(Fields.lineSpacing.name(), this.lineSpacing); jsonObject.put(Fields.fullScreen.name(), this.fullScreen); jsonObject.put(Fields.allowStyling.name(), this.allowStyling); jsonObject.put(Fields.algorithmVersion.name(), this.algorithmVersion); jsonObject.put(Fields.offsets.name(), new JSONArray(this.offsets)); return jsonObject.toString(); }
From source file:net.zorgblub.typhon.dto.PageOffsets.java
private static List<List<Integer>> readOffsets(JSONArray jsonArray) throws JSONException { List<List<Integer>> result = new ArrayList<List<Integer>>(); for (int i = 0; i < jsonArray.length(); i++) { List<Integer> sublist = new ArrayList<>(); JSONArray subArray = new JSONArray(jsonArray.getString(i)); for (int j = 0; j < subArray.length(); j++) { int val = subArray.getInt(j); sublist.add(val); }// w ww .java 2 s .co m result.add(sublist); } return result; }
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 ww w.j av a2 s . co 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 addCaseListOfItems() { RequestParams params = null;//from w w w .j a v a 2 s . c o m params = new RequestParams(); RestService.post(METHOD_ADDCASE_ITEMLIST, 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("Add Case List Item Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonItemList = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); itemCode = jsonResponse.getString("ItemCode").toString(); itemName = jsonResponse.getString("ItemName").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> addCaseItemList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND ADD CASE ITEM LIST"); addCaseItemList.put("ItemCode_T", itemCode); System.out.println(itemCode); addCaseItemList.put("ItemName_T", itemName); System.out.println(itemName); System.out.println(" END ADD CASE ITEM LIST"); jsonItemList.add(addCaseItemList); System.out.println("JSON ADD CASE ITEM LIST"); System.out.println(jsonItemList); } } catch (JSONException e) { // TODO Auto-generated // catch // block e.printStackTrace(); } //Toast.makeText(AddCaseStep2of4.this, "AddCase Item Found", Toast.LENGTH_SHORT).show(); dialog.dismiss(); // Simple Adapter for List SimpleAdapter simpleAdapter = new SimpleAdapter(AddCaseStep2of4.this, jsonItemList, R.layout.listview_column_addcase_itemlist, new String[] { "ItemCode_T", "ItemName_T" }, new int[] { R.id.listAddCaseHeader_ItemCodeText, R.id.listAddCaseHeader_ItemNameText }); listViewItem.setAdapter(simpleAdapter); listViewItem.setOnItemClickListener(new AdapterView.OnItemClickListener() { View ls = null; @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (get() != view && get() != null) { get().setActivated(false); } //Toast.makeText(AddCaseStep2of4.this, "You Clicked at " + jsonItemList.get(position), // Toast.LENGTH_SHORT).show(); System.out.println(position); //int mSelectedItem = position; view.setActivated(true); // Get list of Item data TextView c = (TextView) view.findViewById(R.id.listAddCaseHeader_ItemCodeText); itemCode = c.getText().toString(); System.out.println(itemCode); TextView D = (TextView) view.findViewById(R.id.listAddCaseHeader_ItemNameText); itemName = D.getText().toString(); String data = (String) parent.getItemAtPosition(position).toString(); System.out.println(data); set(view); //store itemname and code in session SharedPreferences prefLogin = getSharedPreferences("ItemData", Context.MODE_PRIVATE); // We need an editor object to make changes SharedPreferences.Editor edit = prefLogin.edit(); // Set/Store data edit.putString("ItemCode", itemCode); edit.putString("ItemName", itemName); // Commit the changes edit.commit(); } private void set(View view) { ls = view; } private View get() { return ls; } }); spinnerpropertyPROJECT.setSelection(2); } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Add Case List Itemparse ParseResponse"); 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 w w .j av a2 s . c om*/ 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; } }); }