List of usage examples for org.json JSONObject optString
public String optString(String key)
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
protected Uri getPictureUriOfGraphObject(JSONObject graphObject) { String uri = null;//from w w w . j av a 2 s. c o m Object o = graphObject.opt(PICTURE); if (o instanceof String) { uri = (String) o; } else if (o instanceof JSONObject) { JSONObject data = ((JSONObject) o).optJSONObject("data"); uri = data != null ? data.optString("url") : null; } if (uri != null) { return Uri.parse(uri); } return null; }
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
/** * @throws FacebookException if the GraphObject doesn't have an ID. *//*from ww w . ja v a2s. c o m*/ String getIdOfGraphObject(JSONObject graphObject) { String id = graphObject.optString(ID); if (id != null) { return id; } throw new FacebookException("Received an object without an ID."); }
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
private static int compareGraphObjects(JSONObject a, JSONObject b, Collection<String> sortFields, Collator collator) {//w ww . ja v a2 s . c o m for (String sortField : sortFields) { String sa = a.optString(sortField); String sb = b.optString(sortField); if (sa != null && sb != null) { int result = collator.compare(sa, sb); if (result != 0) { return result; } } else if (!(sa == null && sb == null)) { return (sa == null) ? -1 : 1; } } return 0; }
From source file:com.util.httpRecargas.java
public List<Recarga> getRecargas(String idAccount, String page, String max, String startDate, String endDate) { // System.out.println("OBTENER SOLO UN ARRAY DE CADENA JSON"); String myURL = "http://192.168.5.44/app_dev.php/cus/recharges/history/" + idAccount + ".json"; // System.out.println("Requested URL:" + myURL); StringBuilder sb = new StringBuilder(); URLConnection urlConn = null; InputStreamReader in = null;/* w w w .j ava 2 s.com*/ try { URL url = new URL(myURL); urlConn = url.openConnection(); if (urlConn != null) { urlConn.setReadTimeout(60 * 1000); urlConn.setDoOutput(true); String data = URLEncoder.encode("page", "UTF-8") + "=" + URLEncoder.encode(page, "UTF-8"); data += "&" + URLEncoder.encode("max", "UTF-8") + "=" + URLEncoder.encode(max, "UTF-8"); data += "&" + URLEncoder.encode("startDate", "UTF-8") + "=" + URLEncoder.encode(startDate, "UTF-8"); data += "&" + URLEncoder.encode("endDate", "UTF-8") + "=" + URLEncoder.encode(endDate, "UTF-8"); System.out.println("los Datos a enviar por POST son " + data); try ( //obtenemos el flujo de escritura OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream())) { //escribimos wr.write(data); wr.flush(); //cerramos la conexin } } if (urlConn != null && urlConn.getInputStream() != null) { in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(in); if (bufferedReader != null) { int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } bufferedReader.close(); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Exception while calling URL:" + myURL, e); } String jsonResult = sb.toString(); System.out.println("DATOS ENVIADOS DEL SERVIDOR " + sb.toString()); // System.out.println("\n\n--------------------OBTENEMOS OBJETO JSON NATIVO DE LA PAGINA, USAMOS EL ARRAY DATA---------------------------\n\n"); JSONObject objJason = new JSONObject(jsonResult); // JSONArray dataJson = new JSONArray(); // dataJson = objJason.getJSONArray("data"); String jdata = objJason.optString("data"); String mensaje = objJason.optString("message"); System.out.println("\n MENSAJE DEL SERVIDOR " + mensaje); // System.out.println(" el objeto jdata es " + jdata); objJason = new JSONObject(jdata); // System.out.println("objeto normal 1 " + objJason.toString()); // jdata = objJason.optString("items"); // System.out.println("\n\n el objeto jdata es " + jdata); JSONArray jsonArray = new JSONArray(); Gson gson = new Gson(); //objJason = gson.t jsonArray = objJason.getJSONArray("items"); // System.out.println("\n\nEL ARRAY FINAL ES " + jsonArray.toString()); /* List<String> list = new ArrayList<String>(); for (int i = 0; i < jsonArray.length(); i++) { list.add(String.valueOf(i)); list.add(jsonArray.getJSONObject(i).getString("created_date")); list.add(jsonArray.getJSONObject(i).getString("description")); list.add(String.valueOf(jsonArray.getJSONObject(i).getInt("credit"))); list.add(jsonArray.getJSONObject(i).getString("before_balance")); list.add(jsonArray.getJSONObject(i).getString("after_balance")); } System.out.println("\n\nel array java contiene "+ list.toString()); */ List<Recarga> recargas = new ArrayList<Recarga>(); for (int i = 0; i < jsonArray.length(); i++) { Recarga recarga = new Recarga(); recarga.setNo(i); recarga.setFecha(jsonArray.getJSONObject(i).getString("created_date")); recarga.setDescripcion(jsonArray.getJSONObject(i).getString("description")); recarga.setMonto(String.valueOf(jsonArray.getJSONObject(i).getInt("credit"))); recarga.setSaldoAnterior(jsonArray.getJSONObject(i).getString("before_balance")); recarga.setSaldoPosterior(jsonArray.getJSONObject(i).getString("after_balance")); recargas.add(recarga); } for (int i = 0; i < recargas.size(); i++) { System.out.print("\n\nNo" + recargas.get(i).getNo()); System.out.print("\nFecna " + recargas.get(i).getFecha()); System.out.print("\nDescripcion " + recargas.get(i).getDescripcion()); System.out.print("\nMonto " + recargas.get(i).getMonto()); System.out.print("\nSaldo Anterior " + recargas.get(i).getSaldoAnterior()); System.out.print("\nSaldo Posterior" + recargas.get(i).getSaldoPosterior()); } return recargas; }
From source file:com.funzio.pure2D.particles.nova.vo.TweenAnimatorVO.java
public TweenAnimatorVO(final JSONObject json) throws JSONException { super(json);//from ww w . j a v a 2 s.c om interpolation = json.optString("interpolation"); reversed = json.optBoolean("reversed", false); duration = NovaVO.getListInt(json, "duration"); }
From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java
private static void addFieldToXml(Element root, Field field, JSONObject in, String permlevel) throws JSONException, UnderlyingStorageException { if (field.isServicesReadOnly()) { // Omit fields that are read-only in the services layer. log.debug("Omitting services-readonly field: " + field.getID()); return;//www.j a v a 2 s . co m } Element element = root; if (field.getUIType().startsWith("groupfield") && field.getUIType().contains("selfrenderer")) { //ignore the top level if this is a self renderer as the UI needs it but the services doesn't } else { element = root.addElement(field.getServicesTag()); } String value = in.optString(field.getID()); if (field.getUIType().startsWith("groupfield")) { if (field.getUIType().contains("selfrenderer")) { addSubRecordToXml(element, field, in, permlevel); } else { if (in.has(field.getID())) { addSubRecordToXml(element, field, in.getJSONObject(field.getID()), permlevel); } } } else if (field.getDataType().equals("boolean")) { // Rather than dump what we have coming in, first convert to proper boolean and back. // Properly handles null, in particular. boolean bool = Boolean.parseBoolean(value); element.addText(Boolean.toString(bool)); } else { element.addText(value); } }
From source file:org.b3log.symphony.model.Character.java
/** * Gets a character by the specified character content in the specified characters. * * @param content the specified character content * @param characters the specified characters * @return character, returns {@code null} if not found *///from ww w . j av a 2s . c o m public static JSONObject getCharacter(final String content, final Set<JSONObject> characters) { for (final JSONObject character : characters) { if (character.optString(CHARACTER_CONTENT).equals(content)) { return character; } } return null; }
From source file:com.photon.phresco.nativeapp.eshop.activity.ProductListActivity.java
/** * Read the products JSON from web server *///from w w w . j a va 2s. c o m private void getProductJSONObject() throws IOException { PhrescoLogger.info(TAG + " Inside getProductJSONObject "); JSONObject jObject = null; Product productObj = new Product(); if (search == null && categoryId != -1) { PhrescoLogger.info(TAG + " Get Products for Category: " + categoryId); jObject = productObj.getProductJSONObject( Constants.getWebContextURL() + Constants.getRestAPI() + Constants.CATEGORIES_URL + categoryId); } else if (search != null) { PhrescoLogger.info(TAG + " Get Products for search phrase: " + search); jObject = productObj.getProductJSONObject(Constants.getWebContextURL() + Constants.getRestAPI() + Constants.PRODUCTS_URL + Constants.SEARCH_URL + search); } try { if (jObject != null) { if (jObject.optString("type") != null && jObject.optString("type").equalsIgnoreCase("failure")) { errorObj = getErrorGSONObject(jObject); } else { productList = productObj.getProductGSONObject(jObject); downloadProductImages(); } } } catch (Exception ex) { PhrescoLogger.info(TAG + "getProductJSONObject : Exception - " + ex.toString()); PhrescoLogger.warning(ex); } }
From source file:fr.cph.stock.android.activity.LoginActivity.java
public void displayError(JSONObject json) { showProgress(false, json.optString("error")); }
From source file:net.digitalphantom.app.weatherapp.data.LocationResult.java
@Override public void populate(JSONObject data) { address = data.optString("formatted_address"); }