List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:com.example.internetofthingsxively.MainActivity.java
@Override protected Boolean doInBackground(Integer... values) { Log.d("TEST", "Ejecutando AsyncTask"); try {/* ww w .j a v a 2s. c om*/ // Objeto JSON para enviar a Xively. JSONObject dataJSON = new JSONObject(); dataJSON.put("version", "1.0.0"); // Objeto JSON que representa el channel de voltaje JSONObject voltajeValue = new JSONObject(); voltajeValue.put("id", "voltaje"); voltajeValue.put("current_value", "" + values[0]); // Objeto JSON que representa el channel de amperios JSONObject amperiosValue = new JSONObject(); amperiosValue.put("id", "amperios"); amperiosValue.put("current_value", "" + values[1]); // Objeto JSON que representa el channel de watios JSONObject watiosValue = new JSONObject(); watiosValue.put("id", "watio"); watiosValue.put("current_value", "" + values[2]); // Los juntamos todos dentro de otro objeto JSON llamado datastreams JSONArray datastreamsJSON = new JSONArray(); datastreamsJSON.put(voltajeValue); datastreamsJSON.put(amperiosValue); datastreamsJSON.put(watiosValue); // Agragamos todo lo que hemos creado al JSON que enviaremos a Xively. dataJSON.put("datastreams", datastreamsJSON); Log.d("TEST", dataJSON.toString()); // Conectar a Xively y enviar. HttpClient httpClient = new DefaultHttpClient(); HttpPut httpPut = new HttpPut("https://api.xively.com/v2/feeds/" + XIVELY_FEED); httpPut.setHeader("X-ApiKey", XIVELY_APIKEY); httpPut.setHeader("content-type", "application/json"); StringEntity entity = new StringEntity(dataJSON.toString()); httpPut.setEntity(entity); HttpResponse httpResponse = httpClient.execute(httpPut); String responseString = EntityUtils.toString(httpResponse.getEntity()); Log.d("TEST", "" + httpResponse.getStatusLine().getStatusCode()); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.lisapark.octopus.util.json.JsonUtils.java
/** * // w ww . ja v a 2 s. c o m * @param row * @param cells * @throws JSONException */ private JSONArray jsonFromRow(Row row) throws JSONException { JSONArray cells = new JSONArray(); for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) { Cell cell = cellsIT.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cells.put(cell.getStringCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { cells.put(cell.getNumericCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { cells.put(cell.getBooleanCellValue()); } else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) { cells.put(cell.getErrorCellValue()); } else { cells.put("N/A"); } } return cells; }
From source file:org.loklak.api.iot.FossasiaPushServlet.java
@Override protected JSONArray extractMessages(JSONObject data) { // each fossasia api file contains only 1 message JSONArray array = new JSONArray(); array.put(data); return array; }
From source file:org.loklak.api.iot.FossasiaPushServlet.java
@Override protected void customProcessing(JSONObject message) { JSONObject location = (JSONObject) message.get("location"); final Double longitude = (Double) location.get("lon"); final Double latitude = (Double) location.get("lat"); JSONArray location_point = new JSONArray(); location_point.put(longitude); location_point.put(latitude);/*from w ww . ja v a 2 s . com*/ message.put("location_point", location_point); message.put("location_mark", location_point); }
From source file:io.github.minime89.passbeam.keyboard.Keysyms.java
public JSONObject dump() throws JSONException { JSONObject obj = new JSONObject(); JSONArray keysymsArr = new JSONArray(); for (Keysym keysym : keysyms) { keysymsArr.put(keysym.dump()); }/*w w w .ja v a 2 s . com*/ obj.put("keysyms", keysymsArr); return obj; }
From source file:xml.JDOMConverter.java
/**. * Handles the case where the object in filter is an array * @param a the filtered array/*from w w w . ja v a2 s . co m*/ * @throws JSONException */ private void handleArray(final String elemName) throws JSONException { if (!skipp) { if (tree.get(current - 1).has(elemName)) { JSONArray jsa = new JSONArray(); jsa.put(tree.get(current - 1).get(elemName)); jsa.put(tree.get(current)); tree.remove(tree.get(current - 1).get(elemName)); tree.get(current - 1).put(elemName, jsa); } else { tree.get(current - 1).put(elemName, tree.get(current)); } } else { skipp = false; } }
From source file:com.github.koraktor.steamcondenser.community.GameItem.java
/** * Creates a new instance of a GameItem with the given data * * @param inventory The inventory this item is contained in * @param itemData The data specifying this item * @throws WebApiException on Web API errors *//*from w w w .jav a 2 s.c om*/ public GameItem(GameInventory inventory, JSONObject itemData) throws SteamCondenserException { this.inventory = inventory; try { this.defindex = itemData.getInt("defindex"); this.backpackPosition = (int) itemData.getLong("inventory") & 0xffff; this.count = itemData.getInt("quantity"); this.craftable = !itemData.optBoolean("flag_cannot_craft"); this.id = itemData.getInt("id"); this.itemClass = this.getSchemaData().getString("item_class"); this.itemSet = this.inventory.getItemSchema().getItemSets() .get(this.getSchemaData().optString("item_set")); this.level = itemData.getInt("level"); this.name = this.getSchemaData().getString("item_name"); this.preliminary = (itemData.getLong("inventory") & 0x40000000) != 0; this.originalId = itemData.getInt("original_id"); this.quality = this.inventory.getItemSchema().getQualities().get(itemData.getInt("quality")); this.tradeable = !itemData.optBoolean("flag_cannot_trade"); this.type = this.getSchemaData().getString("item_type_name"); if (itemData.has("origin")) { this.origin = this.inventory.getItemSchema().getOrigins().get(itemData.getInt("origin")); } JSONArray attributesData = this.getSchemaData().optJSONArray("attributes"); if (attributesData == null) { attributesData = new JSONArray(); } if (itemData.has("attributes")) { JSONArray itemAttributes = itemData.getJSONArray("attributes"); for (int i = 0; i < itemAttributes.length(); i++) { attributesData.put(itemAttributes.get(i)); } } this.attributes = new ArrayList<JSONObject>(); for (int i = 0; i < attributesData.length(); i++) { JSONObject attributeData = attributesData.getJSONObject(i); Object attributeKey = attributeData.opt("defindex"); if (attributeKey == null) { attributeKey = attributeData.opt("name"); } if (attributeKey != null) { JSONObject schemaAttributeData = inventory.getItemSchema().getAttributes().get(attributeKey); for (String key : JSONObject.getNames(schemaAttributeData)) { attributeData.put(key, schemaAttributeData.get(key)); } this.attributes.add(attributeData); } } } catch (JSONException e) { throw new WebApiException("Could not parse JSON data.", e); } }
From source file:com.grillecube.common.utils.JSONHelper.java
public static JSONArray vector3fToJSONArray(Vector3f vec) { JSONArray array = new JSONArray(); array.put(vec.getX()); array.put(vec.getY());// ww w . ja va 2s . co m array.put(vec.getZ()); return (array); }
From source file:com.grillecube.common.utils.JSONHelper.java
public static <T> JSONArray arrayToJSONArray(T[] array) { JSONArray jsonarray = new JSONArray(); if (array == null) { return (null); }/*from w ww .jav a 2 s. c o m*/ for (T t : array) { jsonarray.put(t); } return (jsonarray); }
From source file:com.grillecube.common.utils.JSONHelper.java
public static JSONArray arrayToJSONArray(byte[] array) { JSONArray jsonarray = new JSONArray(); if (array == null) { return (null); }/* ww w . java 2 s .co m*/ for (byte b : array) { jsonarray.put(b); } return (jsonarray); }