List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:pgentity.GiftTemplate.java
public static GiftTemplate newTemplate(String templID, Map<String, Object> giftData, int giftExpire, int templExpire) { PGException.Assert(!isExist(templID), PGError.UNDEFINED, "Gift template are already existed"); GiftTemplate giftTemplate = new GiftTemplate(templID); giftTemplate.setGiftData(JSONValue.toJSONString(giftData)); giftTemplate.setGiftExpire(giftExpire); giftTemplate.saveToDB();//from ww w. j a v a 2 s .c om giftTemplate.expireKey(templExpire); EntityPool.inst().put(giftTemplate, GiftTemplate.class, templID); return giftTemplate; }
From source file:pgentity.Notification.java
public void send(String type, Object data) { this.push(JSONValue.toJSONString(AMFBuilder.make("type", type, PGMacro.DATA, data))); }
From source file:pgentity.services.GiftServices.java
public Gift sendGift(Collection<String> receivers, Map<String, Object> giftPrize, long now, int expired) { try {/*from w w w. j a v a 2s . c om*/ PrizeFactory.getPrize(giftPrize); } catch (Exception ex) { PGException.Assert(false, PGError.INVALID_GIFT, "Invalid gift prize " + JSONValue.toJSONString(giftPrize)); } String giftID = PGKeys.randomKey(); Gift gift = Gift.newGift(giftID, giftPrize, now, expired); for (String uid : receivers) { UserGifts userGifts = UserGifts.getGift(uid); userGifts.add(giftID); } return gift; }
From source file:pgentity.services.PaymentServices.java
public void addPayment(String billNo, String uid, String zingCreID, int zingCoin, int gameCoin) { this.addPayment(billNo, uid, zingCreID, zingCoin, gameCoin, 3 * 24 * 60 * 60); // expire 3 days String logData = JSONValue.toJSONString(AMFBuilder.make("zCoin", zingCoin, "pCoin", gameCoin)); Logging.log(new PGRecord(PGLogCategory.PAY, uid, System.currentTimeMillis(), 0, logData)); }
From source file:piuk.blockchain.android.MyWallet.java
public String toJSONString() { return JSONValue.toJSONString(root); }
From source file:pl.nask.hsn2.jsontemplate.formatters.JsStringFormatter.java
@Override public final Object format(Object value) { String jsonString = JSONValue.toJSONString(value); String result = escapeSlashAndUnicode(jsonString); // If value is Number result will be JSON number, which means no quotation marks. Return value has to be JSON // text, so it have to be enclosed within quotation marks. if (!result.startsWith("\"")) { result = "\"" + result + "\""; }//from w ww. java 2 s . c o m return result; }
From source file:Search.DataManipulation.DataParser.java
public String getThumbnails(Document dom) throws IOException { Elements thumbnailsClass = dom.getElementsByClass("thumbnails"); Elements thumbnails = thumbnailsClass.first().children(); List<String> imageArray = new ArrayList<String>(); for (Element images : thumbnails) { String imageTagUrl = images.getElementsByTag("img").first().attr("src"); byte[] imageByte = dataHandler.imageDownloader(imageTagUrl); if (imageByte.length == 0) { continue; }//from w w w . j av a 2s .c o m String imageTag = Base64.getEncoder().encodeToString(imageByte); imageArray.add(imageTag); } return JSONValue.toJSONString(imageArray); }
From source file:Servlet.product.java
private String getResults(String query, String... params) { StringBuilder sb = new StringBuilder(); String json = ""; try (Connection conn = Credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }/*from ww w . j av a 2s. com*/ ResultSet rs = pstmt.executeQuery(); List li = new LinkedList(); while (rs.next()) { //sb.append(String.format("%s\t%s\t%s\t%s\n", rs.getInt("productID"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"))); //for conversion to json https://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar Map m1 = new LinkedHashMap(); m1.put("ProductID", rs.getInt("ProductID")); m1.put("name", rs.getString("name")); m1.put("description", rs.getString("description")); m1.put("quantity", rs.getInt("quantity")); li.add(m1); } json = JSONValue.toJSONString(li); } catch (SQLException ex) { Logger.getLogger(product.class.getName()).log(Level.SEVERE, null, ex); } return json.replace("},", "},\n"); }
From source file:Servlet.webServlet.java
private String getResults(String query, String... params) { StringBuilder sb = new StringBuilder(); String json = ""; try (Connection conn = Credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); }/*from w ww . j a v a 2s.c om*/ ResultSet rs = pstmt.executeQuery(); List li = new LinkedList(); while (rs.next()) { //sb.append(String.format("%s\t%s\t%s\t%s\n", rs.getInt("productID"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"))); //for conversion to json https://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar Map m1 = new LinkedHashMap(); m1.put("ProductID", rs.getInt("ProductID")); m1.put("name", rs.getString("name")); m1.put("description", rs.getString("description")); m1.put("quantity", rs.getInt("quantity")); li.add(m1); } json = JSONValue.toJSONString(li); } catch (SQLException ex) { Logger.getLogger(webServlet.class.getName()).log(Level.SEVERE, null, ex); } return json.replace("},", "},\n"); }
From source file:Servlets.Product.java
/** * resultMethod accepts two arguments It executes the Query get ProductID, * name, description, quantity/* ww w. ja v a 2s.co m*/ * * @param query * @param params * @throws SQLException * @return */ private String resultMethod(String query, String... params) { StringBuilder sb = new StringBuilder(); String jsonString = ""; try (Connection conn = Credentials.getConnection()) { PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } ResultSet rs = pstmt.executeQuery(); List l1 = new LinkedList(); while (rs.next()) { //Refernce Example 5-2 - Combination of JSON primitives, Map and List //https://code.google.com/p/json-simple/wiki/EncodingExamples Map m1 = new LinkedHashMap(); m1.put("ProductID", rs.getInt("ProductID")); m1.put("name", rs.getString("name")); m1.put("description", rs.getString("description")); m1.put("quantity", rs.getInt("quantity")); l1.add(m1); } jsonString = JSONValue.toJSONString(l1); } catch (SQLException ex) { System.err.println("SQL Exception Error: " + ex.getMessage()); } return jsonString.replace("},", "},\n"); }