List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:org.seadpdt.impl.ROServicesImpl.java
@GET @Path("/new/") @Produces(MediaType.APPLICATION_JSON)// w ww. j a v a 2 s. com public Response getNewROsList(@QueryParam("Purpose") final String purpose) { //Find ROs that have a status not from the services and don't include them :-) Document reporterRule = new Document("$ne", Constants.serviceName); Document reporter = new Document("reporter", reporterRule); Document elem = new Document("$elemMatch", reporter); Document not = new Document("$not", elem); Document match = new Document("Status", not); FindIterable<Document> iter; if (purpose != null && purpose.equals("Production")) { iter = publicationsCollection .find(Filters.and(match, Filters.ne("Preferences.Purpose", "Testing-Only"))); } else if (purpose != null && purpose.equals("Testing-Only")) { iter = publicationsCollection.find(Filters.and(match, Filters.eq("Preferences.Purpose", purpose))); } else if (purpose != null) { return Response.status(ClientResponse.Status.BAD_REQUEST) .entity(new JSONObject() .put("Error", "'" + purpose + "' is not an acceptable value for 'Purpose'").toString()) .build(); } else { iter = publicationsCollection.find(match); } iter.projection(new Document("Status", 1).append("Repository", 1).append("Aggregation.Identifier", 1) .append("Aggregation.Title", 1).append("_id", 0)); MongoCursor<Document> cursor = iter.iterator(); JSONArray array = new JSONArray(); while (cursor.hasNext()) { array.put(JSON.parse(cursor.next().toJson())); } return Response.ok(array.toString()).cacheControl(control).build(); }
From source file:com.intel.iotkitlib.LibModules.AdvancedDataEnquiry.java
private String createBodyForAdvancedDataInquiry() throws JSONException { JSONObject dataInquiryJson = new JSONObject(); if (this.msgType == null) { dataInquiryJson.put("msgType", "advancedDataInquiryRequest"); } else {//from w ww .j a v a 2 s .c om dataInquiryJson.put("msgType", this.msgType); } if (this.gatewayIds != null) { JSONArray gatewayArray = new JSONArray(); for (String gatewayId : this.gatewayIds) { gatewayArray.put(gatewayId); } dataInquiryJson.put("gatewayIds", gatewayArray); } if (this.deviceIds != null) { JSONArray deviceIdArray = new JSONArray(); for (String deviceId : this.deviceIds) { deviceIdArray.put(deviceId); } dataInquiryJson.put("deviceIds", deviceIdArray); } if (this.componentIds != null) { JSONArray componentIdArray = new JSONArray(); for (String componentId : this.componentIds) { componentIdArray.put(componentId); } dataInquiryJson.put("componentIds", componentIdArray); } dataInquiryJson.put("startTimestamp", this.startTimestamp); dataInquiryJson.put("endTimestamp", this.endTimestamp); /*dataInquiryJson.put("from", this.startTimestamp); dataInquiryJson.put("to", this.endTimestamp);*/ //returnedMeasureAttributes if (this.returnedMeasureAttributes != null) { JSONArray returnedMeasureAttributesArray = new JSONArray(); for (String attribute : this.returnedMeasureAttributes) { returnedMeasureAttributesArray.put(attribute); } dataInquiryJson.put("returnedMeasureAttributes", returnedMeasureAttributesArray); } if (this.showMeasureLocation) { dataInquiryJson.put("showMeasureLocation", this.showMeasureLocation); } if (this.componentRowLimit > 0) { dataInquiryJson.put("componentRowLimit", this.componentRowLimit); } //sort if (this.sort != null) { JSONArray sortArray = new JSONArray(); for (NameValuePair nameValuePair : this.sort) { JSONObject nameValueJson = new JSONObject(); nameValueJson.put(nameValuePair.getName(), nameValuePair.getValue()); sortArray.put(nameValueJson); } dataInquiryJson.put("sort", sortArray); } if (this.countOnly) { dataInquiryJson.put("countOnly", this.countOnly); } if (this.devCompAttributeFilter != null) { JSONObject devCompAttributeJson = new JSONObject(); for (AttributeFilter attributeFilter : this.devCompAttributeFilter.filterData) { JSONArray filterValuesArray = new JSONArray(); for (String filterValue : attributeFilter.filterValues) { filterValuesArray.put(filterValue); } devCompAttributeJson.put(attributeFilter.filterName, filterValuesArray); } dataInquiryJson.put("devCompAttributeFilter", devCompAttributeJson); } if (this.measurementAttributeFilter != null) { JSONObject measurementAttributeJson = new JSONObject(); for (AttributeFilter attributeFilter : this.measurementAttributeFilter.filterData) { JSONArray filterValuesArray = new JSONArray(); for (String filterValue : attributeFilter.filterValues) { filterValuesArray.put(filterValue); } measurementAttributeJson.put(attributeFilter.filterName, filterValuesArray); } dataInquiryJson.put("measurementAttributeFilter", measurementAttributeJson); } if (this.valueFilter != null) { JSONObject valueFilterJson = new JSONObject(); JSONArray filterValuesArray = new JSONArray(); for (String filterValue : this.valueFilter.filterValues) { filterValuesArray.put(filterValue); } valueFilterJson.put(this.valueFilter.filterName, filterValuesArray); dataInquiryJson.put("valueFilter", valueFilterJson); } return dataInquiryJson.toString(); }
From source file:com.percolatestudio.cordova.fileupload.PSFileUpload.java
private static void addHeadersToRequest(URLConnection connection, JSONObject headers) { try {/*from ww w.j av a 2s. c o m*/ for (Iterator<?> iter = headers.keys(); iter.hasNext();) { String headerKey = iter.next().toString(); JSONArray headerValues = headers.optJSONArray(headerKey); if (headerValues == null) { headerValues = new JSONArray(); headerValues.put(headers.getString(headerKey)); } connection.setRequestProperty(headerKey, headerValues.getString(0)); for (int i = 1; i < headerValues.length(); ++i) { connection.addRequestProperty(headerKey, headerValues.getString(i)); } } } catch (JSONException e1) { // No headers to be manipulated! } }
From source file:org.chromium.ChromeSystemDisplay.java
private void getInfo(final CordovaArgs args, final CallbackContext callbackContext) { cordova.getThreadPool().execute(new Runnable() { @Override/*from w w w. jav a2 s . com*/ public void run() { try { JSONArray ret = new JSONArray(); try { DisplayManager displayManager = (DisplayManager) cordova.getActivity() .getSystemService(Activity.DISPLAY_SERVICE); Display[] displays = displayManager.getDisplays(); for (Display display : displays) { JSONObject displayInfo = new JSONObject(); displayInfo = getDisplayInfo(display); ret.put(displayInfo); } } catch (NoClassDefFoundError e) { Display defaultDisplay = cordova.getActivity().getWindowManager().getDefaultDisplay(); JSONObject displayInfo = new JSONObject(); displayInfo = getDisplayInfo(defaultDisplay); ret.put(displayInfo); } callbackContext.success(ret); } catch (Exception e) { Log.e(LOG_TAG, "Error occured while getting display info", e); callbackContext.error("Could not get display info"); } } }); }
From source file:com.jennifer.ui.util.scale.LinearScale.java
public JSONArray ticks(int count, boolean isNice, int intNumber) { JSONArray list = new JSONArray(); JSONArray domain = domain();//from ww w .j av a 2 s . c o m if (domain.getDouble(0) == 0 && domain.getDouble(1) == 0) { return new JSONArray(); } JSONArray arr = MathUtil.nice(domain.getDouble(0), domain.getDouble(1), count, isNice); double min = arr.getDouble(0); double max = arr.getDouble(1); double range = arr.getDouble(2); double spacing = arr.getDouble(3); double start = min * intNumber; double end = max * intNumber; while (start <= end) { list.put(start / intNumber); start += spacing * intNumber; } if (list.getDouble(list.length() - 1) * intNumber != end && start > end) { list.put(end / intNumber); } return list; }
From source file:com.muzima.service.PreferenceService.java
protected String serialize(Collection<String> values) { if (values == null) { return null; }// w ww . j av a 2 s. c o m JSONArray jsonArray = new JSONArray(); for (String cohort : values) { jsonArray.put(cohort); } return jsonArray.toString(); }
From source file:org.loklak.harvester.YoutubeScraper.java
private static void addRDF(String[] spo, JSONObject json) { if (spo == null) return;/*from www . j a v a2s .c o m*/ String subject = spo[0]; String predicate = spo[1]; String object = CharacterCoding.html2unicode(spo[2]); if (subject.length() == 0 || predicate.length() == 0 || object.length() == 0) return; String key = subject + "_" + predicate; JSONArray objects = null; try { objects = json.getJSONArray(key); } catch (JSONException e) { objects = new JSONArray(); json.put(key, objects); } // double-check (wtf why is ths that complex?) for (Object o : objects) { if (o instanceof String && ((String) o).equals(object)) return; } // add the object to the objects objects.put(object); }
From source file:com.nginious.http.serialize.JsonBeanCollectionSerializer.java
/** * Serializes the specified collection of bean elements into a JSON array. * /* w w w . j a va 2s. co m*/ * @param items the given collection of beans to serialize * @return the serialized JSON array * @throws SerializerException if unable to serialize collection */ public JSONArray serialize(Collection<E> items) throws SerializerException { if (items == null) { return null; } JSONArray array = new JSONArray(); for (E item : items) { JSONObject object = elementSerializer.serialize(item); array.put(object); } return array; }
From source file:feedme.controller.UpdateCategoryServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*www. ja v a 2 s . co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); String city = request.getParameter("city"); HashMap<String, Integer> cat = new DbHPOnLoad().getCategoriesByCity(city); try { JSONObject catObj = new JSONObject(); catObj.put("categorys", new JSONArray()); JSONArray cate = catObj.getJSONArray("categorys"); for (Map.Entry<String, Integer> entry : cat.entrySet()) { cate.put(new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey())); } response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(catObj); response.getWriter().flush(); } catch (JSONException ex) { Logger.getLogger(OrderCompleteServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.asd.littleprincesbeauty.data.SqlNote.java
public JSONObject getContent() { try {/*from w ww . j a va 2 s . c om*/ JSONObject js = new JSONObject(); if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); return null; } JSONObject note = new JSONObject(); if (mType == Notes.TYPE_NOTE) { note.put(NoteColumns.ID, mId); note.put(NoteColumns.ALERTED_DATE, mAlertDate); note.put(NoteColumns.BG_COLOR_ID, mBgColorId); note.put(NoteColumns.CREATED_DATE, mCreatedDate); note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment); note.put(NoteColumns.MODIFIED_DATE, mModifiedDate); note.put(NoteColumns.PARENT_ID, mParentId); note.put(NoteColumns.SNIPPET, mSnippet); note.put(NoteColumns.TYPE, mType); note.put(NoteColumns.WIDGET_ID, mWidgetId); note.put(NoteColumns.WIDGET_TYPE, mWidgetType); note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent); js.put(GTaskStringUtils.META_HEAD_NOTE, note); JSONArray dataArray = new JSONArray(); for (SqlData sqlData : mDataList) { JSONObject data = sqlData.getContent(); if (data != null) { dataArray.put(data); } } js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { note.put(NoteColumns.ID, mId); note.put(NoteColumns.TYPE, mType); note.put(NoteColumns.SNIPPET, mSnippet); js.put(GTaskStringUtils.META_HEAD_NOTE, note); } return js; } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } return null; }