List of usage examples for com.google.gson JsonArray getAsString
@Override
public String getAsString()
From source file:com.mdlive.sav.MDLiveSearchProvider.java
/** * Successful Response Handler for getting Current Location *//*from w w w.j a v a2 s . com*/ private void handleFilterSuccessResponse(JSONObject response) { try { hideProgress(); JsonParser parser = new JsonParser(); JsonObject responObj = (JsonObject) parser.parse(response.toString()); if (!responObj.isJsonNull()) { JsonArray responArray = responObj.get("physicians").getAsJsonArray(); if (responArray.size() != 0) { if (responArray.get(0).isJsonObject()) { Log.e("Filter Response", responObj.toString()); Intent intent = new Intent(); intent.putExtra("Response", response.toString()); intent.putExtra("postParams", new Gson().toJson(postParams)); setResult(1, intent); finish(); MdliveUtils.closingActivityAnimation(MDLiveSearchProvider.this); } else { Log.e("Filter Response", responObj.toString()); MdliveUtils.showDialog(MDLiveSearchProvider.this, responArray.getAsString(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.shareif.bungeeCordDynamicServerPool.RestServer.java
@GET @Path("/list") @Produces(MediaType.APPLICATION_JSON)//from w ww.j ava2 s.com public String get(@HeaderParam("signature") String _signature, @HeaderParam("time") int _time) throws IOException, NoSuchAlgorithmException { if (!WebServer.getInstance().validateAuthToken(_signature, _time, "/cluster/list", "GET")) { throw new WebApplicationException(401); } Map<String, ServerInfo> cluster = ClusterManager.getInstance().getServers(); JsonArray output = new JsonArray(); for (ServerInfo server : cluster.values()) { JsonObject s = new JsonObject(); s.addProperty("name", server.getName()); s.addProperty("motd", server.getMotd()); s.addProperty("address", server.getAddress().getAddress().toString()); s.addProperty("port", server.getAddress().getPort()); s.addProperty("players", server.getPlayers().size()); output.add(s); } return output.getAsString(); }
From source file:com.vmware.eucenablement.horizontoolset.av.api.impl.VolumeImpl.java
/** * Expand a writable volume// ww w . j a v a 2 s .c o m * * @param ID for writable volume * * @return if success, ExcuteResult.resultFlag is RES_SUCCESS. if failure, * this field is other values. */ public ExcuteResult expandWritableVolume(Long writeVolume_id, Long volumeSize) { ExcuteResult resultExcuted = new ExcuteResult(); String msgDescription = ""; Map<String, String> map_expandParameters = new HashMap<String, String>(); map_expandParameters.put("size_mb", volumeSize.toString()); map_expandParameters.put("volumes[]", writeVolume_id.toString()); try { String result = volumeHelper.requestProcess(map_expandParameters, "cv_api/writables/grow", HTTPMethod.POST); JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(result).getAsJsonObject(); JsonArray jsonSuccesses = jsonObject.getAsJsonArray("successes"); JsonArray jsonWarnings = jsonObject.getAsJsonArray("warnings"); JsonArray jsonErrors = jsonObject.getAsJsonArray("errors"); if ((jsonSuccesses != null) && (jsonSuccesses.size() > 0)) { resultExcuted.resultFlag = ExcuteResult.RES_SUCCESS; msgDescription += jsonSuccesses.getAsString(); } else if ((jsonWarnings != null) && (jsonWarnings.size() > 0)) { resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE; msgDescription += jsonWarnings.getAsString(); } else if ((jsonErrors != null) && (jsonErrors.size() > 0)) { resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE; msgDescription += jsonErrors.getAsString(); } else { LOG.warn(new Date().toString() + ": can not expand writable volumes"); resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE; msgDescription += "Can not expand writable volumes."; } } catch (Exception e) { LOG.error(new Date().toString() + ": can not unassign app stack to users: " + e); resultExcuted.resultFlag = ExcuteResult.RES_GENERAL_FAILURE; msgDescription = "Can not expand writable volumes. Exceptions: " + e; } resultExcuted.message = msgDescription; return resultExcuted; }