List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
public ProductsMaster getJVoidProduct(int productId) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); JSONObject jsonObj = new JSONObject(); try {//w ww.j a va2 s . c om jsonObj.put("id", productId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("param jsonObj=>" + jsonObj.toString()); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(PRODUCT_SERVER_URI + URIConstants.GET_PRODUCT).queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); System.out.println("returnString=>" + returnString); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(returnString.getBody()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray productsArr = null; ProductsMaster productsMaster = null; try { productsArr = returnJsonObj.getJSONArray("products"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } productsMaster = new ProductsMaster(); try { ObjectMapper mapper = new ObjectMapper(); try { productsMaster = mapper.readValue(productsArr.getJSONObject(0).toString(), ProductsMaster.class); } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return productsMaster; }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/cart", method = RequestMethod.GET) public @ResponseBody String getCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { //System.out.println("TOTAL RECS1:"+this.productsMasterService.getAllProducts().size()); int cartId = -1; try {/* w ww .ja va 2 s . com*/ cartId = jsonParams.getInt("cartId"); } catch (JSONException e) { e.printStackTrace(); } JSONObject cartObject = new JSONObject(); JSONArray quoteItems = new JSONArray(); List<CheckoutQuoteItem> quoteItemsList = null; quoteItemsList = this.checkoutQuoteItemService.listCheckoutQuoteItems(cartId); System.out.println("ABHI Quote Item List Count= " + quoteItemsList.size()); ObjectMapper mapper = new ObjectMapper(); for (int i = 0; i < quoteItemsList.size(); i++) { try { String strQuoteItemObj = mapper.writeValueAsString(quoteItemsList.get(i)); JSONObject jsonObj = new JSONObject(strQuoteItemObj); quoteItems.put(jsonObj); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } CheckoutQuote currentQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); try { cartObject.put("items", quoteItems); cartObject.put("total", currentQuote.getGrandTotal()); } catch (JSONException e1) { e1.printStackTrace(); } return cartObject.toString(); }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/delete", method = RequestMethod.GET) public @ResponseBody String deleteCart(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { // String jstr = "{\"cartId\":-1, \"productId\":2, \"attributeId\":1, \"quantity\":2}"; // String jstr = "{\"cartId\":1, \"productId\":3, \"attributeId\":1, \"quantity\":2}"; System.out.println("Inside delete"); int cartId = -1; int productId = -1; try {//from w ww .j ava 2s. c o m cartId = jsonParams.getInt("cartId"); productId = jsonParams.getInt("productId"); } catch (JSONException e) { e.printStackTrace(); } // cartId = 1; // productId = -1; CheckoutQuoteItem quoteItemToDelete = null; CheckoutQuote checkoutQuote = new CheckoutQuote(); List<CheckoutQuoteItem> quoteItemsList = null; if (productId != -1) { quoteItemToDelete = this.checkoutQuoteItemService.getCheckoutQuoteItem(cartId, productId); quoteItemsList = new ArrayList<CheckoutQuoteItem>(); quoteItemsList.add(quoteItemToDelete); } else { quoteItemsList = this.checkoutQuoteItemService.listCheckoutQuoteItems(cartId); System.out.println("ABHI Quote Item List Count= " + quoteItemsList.size()); } checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); for (int i = 0; i < quoteItemsList.size(); i++) { CheckoutQuoteItem currentQuoteItemToDelete = quoteItemsList.get(i); checkoutQuote.setItemsCount(checkoutQuote.getItemsCount() - 1); checkoutQuote .setItemsQuantity(checkoutQuote.getItemsQuantity() - currentQuoteItemToDelete.getQuantity()); checkoutQuote .setBaseSubtotal(checkoutQuote.getBaseSubtotal() - currentQuoteItemToDelete.getBaseRowTotal()); checkoutQuote.setSubtotal(checkoutQuote.getSubtotal() - currentQuoteItemToDelete.getRowTotal()); this.checkoutQuoteItemService.removeCheckoutQuoteItem(currentQuoteItemToDelete.getId()); } checkoutQuote.setBaseGrandTotal(checkoutQuote.getBaseSubtotal() + 50); checkoutQuote.setGrandTotal(checkoutQuote.getSubtotal() + 50); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); System.out.println("Abhi checkoutquote after = " + checkoutQuote.toString()); int returnCartId = cartId; if (productId == -1) { this.checkoutQuoteService.removeCheckoutQuote(checkoutQuote.getId()); returnCartId = -1; } else { this.checkoutQuoteService.addCheckoutQuote(checkoutQuote); } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", returnCartId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }
From source file:com.jvoid.quote.controller.JVoidQuoteController.java
@RequestMapping(value = "quote/addaddress", method = RequestMethod.GET) public @ResponseBody String addAddress(@RequestParam(required = false, value = "callback") String callback, @RequestParam(required = false, value = "params") JSONObject jsonParams, HttpServletResponse response) { int cartId = -1; JSONObject user = null;/*from www . ja v a2 s . co m*/ JSONObject billing = null; JSONObject shipping = null; String checkoutMethod = null; try { cartId = jsonParams.getInt("cartId"); user = jsonParams.getJSONObject("user"); billing = jsonParams.getJSONObject("billing"); shipping = jsonParams.getJSONObject("shipping"); checkoutMethod = jsonParams.getString("checkoutMethod"); } catch (JSONException e) { e.printStackTrace(); } CheckoutQuote checkoutQuote = this.checkoutQuoteService.getCheckoutQuoteById(cartId); checkoutQuote.setCheckoutMethod(checkoutMethod); checkoutQuote.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteService.updateCheckoutQuote(checkoutQuote); try { CheckoutQuoteAddress checkoutQuoteAddress = new CheckoutQuoteAddress(); checkoutQuoteAddress.setQuoteId(cartId); checkoutQuoteAddress.setFirstname(user.getString("firstName")); checkoutQuoteAddress.setLastname(user.getString("lastName")); checkoutQuoteAddress.setCompany(user.getString("company")); checkoutQuoteAddress.setEmail(user.getString("emailAddress")); checkoutQuoteAddress.setAddressType("billing"); checkoutQuoteAddress .setStreet(billing.getString("address") + "," + billing.getString("streetAddress2")); checkoutQuoteAddress.setCity(billing.getString("city") + "," + billing.getString("state")); checkoutQuoteAddress.setCountryId(billing.getString("country")); checkoutQuoteAddress.setPostcode(billing.getString("zip")); checkoutQuoteAddress.setTelephone(billing.getString("telephone")); checkoutQuoteAddress.setFax(billing.getString("fax")); checkoutQuoteAddress.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuoteAddress.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteAddressService.addCheckoutQuoteAddress(checkoutQuoteAddress); checkoutQuoteAddress = null; checkoutQuoteAddress = new CheckoutQuoteAddress(); checkoutQuoteAddress.setQuoteId(cartId); checkoutQuoteAddress.setFirstname(user.getString("firstName")); checkoutQuoteAddress.setLastname(user.getString("lastName")); checkoutQuoteAddress.setCompany(user.getString("company")); checkoutQuoteAddress.setEmail(user.getString("emailAddress")); checkoutQuoteAddress.setAddressType("shipping"); checkoutQuoteAddress .setStreet(shipping.getString("address") + "," + shipping.getString("streetAddress2")); checkoutQuoteAddress.setCity(shipping.getString("city") + "," + shipping.getString("state")); checkoutQuoteAddress.setCountryId(shipping.getString("country")); checkoutQuoteAddress.setPostcode(shipping.getString("zip")); checkoutQuoteAddress.setTelephone(shipping.getString("telephone")); checkoutQuoteAddress.setFax(shipping.getString("fax")); checkoutQuoteAddress.setCreatedAt(Utilities.getCurrentDateTime()); checkoutQuoteAddress.setUpdatedAt(Utilities.getCurrentDateTime()); this.checkoutQuoteAddressService.addCheckoutQuoteAddress(checkoutQuoteAddress); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jsonObj = new JSONObject(); try { jsonObj.put("cartId", cartId); jsonObj.put("result", "Success"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObj.toString(); }
From source file:com.intel.iotkitlib.LibModules.AccountManagement.java
public boolean createAnAccount(String accountName) { if (accountName == null) { Log.d(TAG, "account Name cannot be empty"); return false; }// www . ja v a 2 s . co m String body = "{\"name\":" + "\"" + accountName + "\"" + "}"; //initiating post for authorization HttpPostTask createAnAccount = new HttpPostTask(new HttpTaskHandler() { @Override public void taskResponse(int responseCode, String response) { Log.d(TAG, String.valueOf(responseCode)); Log.d(TAG, response); try { AuthorizationToken.parseAndStoreAccountIdAndName(response); } catch (JSONException e) { e.printStackTrace(); } statusHandler.readResponse(responseCode, response); } }); createAnAccount.setHeaders(basicHeaderList); createAnAccount.setRequestBody(body); String url = objIotKit.prepareUrl(objIotKit.createAnAccount, null); return super.invokeHttpExecuteOnURL(url, createAnAccount, "create account"); }
From source file:com.intel.iotkitlib.LibModules.AccountManagement.java
public boolean updateAnAccount(final String accountNameToUpdate) { //initiating put for update of account HttpPutTask updateAccount = new HttpPutTask(new HttpTaskHandler() { @Override/*from w w w .j av a 2 s. co m*/ public void taskResponse(int responseCode, String response) { Log.d(TAG, String.valueOf(responseCode)); Log.d(TAG, response); statusHandler.readResponse(responseCode, response); try { AuthorizationToken.parseAndStoreAccountName(accountNameToUpdate, responseCode); } catch (JSONException e) { e.printStackTrace(); } } }); updateAccount.setHeaders(basicHeaderList); //populating the JSON body of account updation String body = null; try { body = Utilities.createBodyForUpdateAccount(accountNameToUpdate); } catch (JSONException e) { e.printStackTrace(); } if (body != null) { updateAccount.setRequestBody(body); } String url = objIotKit.prepareUrl(objIotKit.updateAccount, null); return super.invokeHttpExecuteOnURL(url, updateAccount, "update account"); }
From source file:it.mb.whatshare.SendToGCMActivity.java
/** * Loads the ID and name of the paired device in use to share content when * Whatsapp is not installed on this device. * //from ww w .j a v a2 s. c o m * @param activity * the calling activity * @return the device loaded from file if any is configured, * <code>null</code> otherwise * @throws OptionalDataException * @throws ClassNotFoundException * @throws IOException */ static Pair<PairedDevice, String> loadOutboundPairing(Context activity) throws OptionalDataException, ClassNotFoundException, IOException { FileInputStream fis = activity.openFileInput("pairing"); Scanner scanner = new Scanner(fis).useDelimiter("\\Z"); JSONObject json; try { json = new JSONObject(scanner.next()); String name = json.getString("name"); String type = json.getString("type"); String assignedID = json.getString("assignedID"); return new Pair<PairedDevice, String>(new PairedDevice(assignedID, name, type), assignedID); } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:com.cssweb.android.view.KlineView.java
public void onDraw(Canvas canvas) { paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(1);// w ww.ja va 2 s .co m tPaint = new Paint(); tPaint.setStyle(Paint.Style.STROKE); tPaint.setTypeface(Typeface.DEFAULT_BOLD); tPaint.setAntiAlias(true); tPaint.setTextSize(dTextSize); // tips = (int) tPaint.measureText("0"); try { if (actualDataLen == 0) { return; } if (zs) axisLabelWidth = (int) Math.max(tPaint.measureText("99999.99"), tPaint.measureText("11000")); else axisLabelWidth = (int) tPaint.measureText("11000"); klineWidth = width - axisLabelWidth; //?spaceWidth??? visualKLineCount = (int) ((klineWidth - spaceWidth) / (spaceWidth + shapeWidth)); if (isSingleMoved == false && isTrackStatus == false) { if (actualDataLen > visualKLineCount) { actualPos = actualDataLen - visualKLineCount; count = visualKLineCount; } else { actualPos = 0; count = actualDataLen; } } //Log.i("@@@@@@@@isTrackStatus@@@@@@@@@", isTrackStatus+">>>>>>"+actualDataLen+">>>>>>"+isTrackNumber + ">>>>>>>>>" + actualPos); calcMaxMin(actualPos); // axisLabelHeight = Font.getFontHeight(dTextSize); klineX = axisLabelWidth; klineY = axisLabelHeight; klineHeight = (int) ((height - axisLabelHeight) * 0.6); volumeHeight = (int) ((height - axisLabelHeight) * 0.4); axisX = klineX; if (!isTrackStatus) { moveQuote(actualDataLen - 1); } else { //isTrackNumber = (isTrackNumber>actualDataLen-1)?actualDataLen-1:isTrackNumber; if (trackLineV == 0) { trackLineV = (int) (visualPos * (spaceWidth + shapeWidth) - shapeWidth / 2); isTrackNumber = actualPos + visualPos - 1; } if (isTrackNumber < 0) { isTrackNumber = 0; } else if (isTrackNumber > actualDataLen - 1) { isTrackNumber = actualDataLen - 1; } paint.setColor(GlobalColor.clrGrayLine); canvas.drawLine(klineX + trackLineV, axisLabelHeight, klineX + trackLineV, height - axisLabelHeight, paint); moveQuote(isTrackNumber); drawQuoteWin(canvas, quoteData, isTrackNumber); } // tPaint.setTextAlign(Paint.Align.LEFT); tPaint.setColor(GlobalColor.colorM5); canvas.drawText(lblIndicatorName, (float) (klineX + tips), axisLabelHeight - 5, tPaint); float size = tPaint.measureText(lblIndicatorName) + tips * 2; tPaint.setColor(GlobalColor.colorM10); canvas.drawText(lblIndicatorT1, (float) (klineX + size), axisLabelHeight - 5, tPaint); size += tPaint.measureText(lblIndicatorT1) + tips; if (size <= (klineWidth - tPaint.measureText(lblIndicatorT2))) { //tPaint.setColor(GlobalColor.colorM20); tPaint.setARGB(255, 255, 0, 255); canvas.drawText(lblIndicatorT2, (float) (klineX + size), axisLabelHeight - 5, tPaint); } size += tPaint.measureText(lblIndicatorT2) + tips; if (size <= (klineWidth - tPaint.measureText(lblIndicatorT3))) { tPaint.setColor(GlobalColor.colorM60); canvas.drawText(lblIndicatorT3, (float) (klineX + size), axisLabelHeight - 5, tPaint); } //? tPaint.setColor(GlobalColor.colorLabelName); canvas.drawText(lblmainIndicatorT1, (float) (klineX + tips), klineY + klineHeight + axisLabelHeight - 5, tPaint); size = tPaint.measureText(lblmainIndicatorT1) + tips * 2; tPaint.setColor(GlobalColor.colorM5); canvas.drawText(lblmainIndicatorT2, (float) (klineX + size), klineY + klineHeight + axisLabelHeight - 5, tPaint); size += tPaint.measureText(lblmainIndicatorT2) + tips; if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT3))) { tPaint.setColor(GlobalColor.colorM10); canvas.drawText(lblmainIndicatorT3, (float) (klineX + size), klineY + klineHeight + axisLabelHeight - 5, tPaint); } size += tPaint.measureText(lblmainIndicatorT3) + tips; if (size <= (klineWidth - tPaint.measureText(lblmainIndicatorT4))) { tPaint.setARGB(255, 255, 0, 255); canvas.drawText(lblmainIndicatorT4, (float) (klineX + size), klineY + klineHeight + axisLabelHeight - 5, tPaint); } //??? rowHeight = klineHeight / rowNum; scale = klineHeight / (highPrice - lowPrice); double ratio = (highPrice - lowPrice) / rowNum; paint.setColor(GlobalColor.clrLine); tPaint.setColor(GlobalColor.colorTicklabel); tPaint.setTextAlign(Paint.Align.RIGHT); for (int i = 0; i <= rowNum; i++) { if (i == rowNum || i == 0) { canvas.drawLine(klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } else { Graphics.drawDashline(canvas, klineX, klineY + rowHeight * i, width, klineY + rowHeight * i, paint); } if (i != rowNum && isTrackStatus == false) { double AxisLabelPrice = highPrice - ratio * i; String AxisLabelPriceText; AxisLabelPriceText = Utils.dataFormation(AxisLabelPrice, stockdigit); canvas.drawText(AxisLabelPriceText, klineX - tips / 4, klineY + rowHeight * i + axisLabelHeight / 2, tPaint); } } // if (quoteData != null) { //axisX = 0; for (int i = actualPos; i < (actualPos + count); i++) { if (i == 0) drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(2), quoteData.getJSONArray("K").getJSONArray(i).getDouble(3), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4)); else drawKLine(canvas, i - actualPos, quoteData.getJSONArray("K").getJSONArray(i).getDouble(1), quoteData.getJSONArray("K").getJSONArray(i).getDouble(2), quoteData.getJSONArray("K").getJSONArray(i).getDouble(3), quoteData.getJSONArray("K").getJSONArray(i).getDouble(4), quoteData.getJSONArray("K").getJSONArray(i - 1).getDouble(4)); } if (mainIndicatorType.toUpperCase().equals("MA")) drawMA(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (mainIndicatorType.toUpperCase().equals("BOLL")) drawBoll(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); rowHeight = (volumeHeight - axisLabelHeight * 2) / rowNum; klineY = klineHeight + axisLabelHeight * 2; volumeHeight = rowNum * rowHeight; if (indicatorType.toUpperCase().equals("VOLUME")) drawVOLUME(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("MACD")) drawMACD(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("CCI")) drawCCI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("BIAS")) drawBIAS(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("KDJ")) drawKDJ(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("RSI")) drawRSI(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("OBV")) drawOBV(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); else if (indicatorType.toUpperCase().equals("PSY")) drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen, "PSY"); else if (indicatorType.toUpperCase().equals("ROC")) drawROC(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen, "ROC"); else if (indicatorType.toUpperCase().equals("VR")) drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen, "VR"); else if (indicatorType.toUpperCase().equals("WR")) drawOther(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen, "WR"); drawTimeAix(canvas, quoteData, actualPos, count, shapeWidth, spaceWidth, highPrice, lowPrice, highVolume, actualDataLen); } //????? paint.setColor(GlobalColor.clrLine); canvas.drawLine(klineX, 0, width, 0, paint); canvas.drawLine(klineX, 0, klineX, height - axisLabelHeight, paint); canvas.drawLine(width, 0, width, height - axisLabelHeight, paint); //canvas.drawLine(klineX, height - axisLabelHeight, width, height - axisLabelHeight, paint); } catch (JSONException e) { e.printStackTrace(); } }
From source file:nl.spellenclubeindhoven.dominionshuffle.Application.java
public void loadResult() { try {/*from ww w .j a va2 s . c om*/ JSONObject jsonResult = new JSONObject(DataReader.readStringFromFile(this, "result.json")); JSONArray jsonCards = jsonResult.getJSONArray("cards"); LinkedList<Card> cards = new LinkedList<Card>(); for (int i = 0; i < jsonCards.length(); i++) { Card card = dataReader.getData().getCard(jsonCards.getString(i)); if (card == null) return; cards.add(card); } Card baneCard = null; Card obeliskCard = null; if (jsonResult.has("baneCard")) { baneCard = dataReader.getData().getCard(jsonResult.getString("baneCard")); } if (jsonResult.has("obeliskCard")) { obeliskCard = dataReader.getData().getCard(jsonResult.getString("obeliskCard")); } result = new Result(); result.setCards(cards); result.setBaneCard(baneCard); result.setObeliskCard(obeliskCard); } catch (JSONException ignore) { ignore.printStackTrace(); } }
From source file:nl.spellenclubeindhoven.dominionshuffle.Application.java
public void saveResult() { if (result == null) return;//from w w w .ja v a2 s. com JSONObject jsonResult = new JSONObject(); JSONArray jsonCards = new JSONArray(); for (Card card : result.getCards()) { jsonCards.put(card.getName()); } try { jsonResult.put("cards", jsonCards); if (result.getBaneCard() != null) { jsonResult.put("baneCard", result.getBaneCard().getName()); } if (result.getObeliskCard() != null) { jsonResult.put("obeliskCard", result.getObeliskCard().getName()); } DataReader.writeStringToFile(this, "result.json", jsonResult.toString()); } catch (JSONException ignore) { ignore.printStackTrace(); } }