List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.epsi.wks.api_wks_back.User.java
@DELETE @Path("/tweet/{tweet_id}") @Produces("application/json") public JSONObject getUserFollowingsTweets(@PathParam("id") long userID, @PathParam("tweet_id") long tweetID) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { JSONObject result = new JSONObject(); result.put("success", true); result.put("message", "No need"); Tweet tweet = new Tweet(tweetID, userID, 2); try {//from ww w . ja va 2 s . co m if (!TweetDao.alreadyRegistered(tweetID, userID)) { TweetDao.insert(tweet); } else { TweetDao.update(tweet); } result.put("success", true); result.put("message", "No need"); } catch (SQLException ex) { result.put("success", false); result.put("message", ex); } return result; }
From source file:io.personium.client.MetadataLinkManager.java
/** * This method is used to create the link. * @param cx Target object to create link * @throws DaoException Exception thrown *//*w ww. j a va 2 s . co m*/ @SuppressWarnings("unchecked") public void link(AbstractODataContext cx) throws DaoException { String uri = getLinkUrl(cx); JSONObject body = new JSONObject(); body.put("uri", cx.getODataLink()); IRestAdapter rest = RestAdapterFactory.create(accessor); rest.post(uri, body.toJSONString(), RestAdapter.CONTENT_TYPE_JSON); }
From source file:naftoreiclag.villagefive.world.entity.Entity.java
public final String toJSONString() { JSONObject obj = new JSONObject(); obj.put("instanceof", this.getEntityId()); obj.put("location", new Vec2(this.node.getLocalTranslation())); this.addAdditionalData(obj); return obj.toJSONString(); }
From source file:com.conwet.silbops.model.ContextFunctionTest.java
@Test @SuppressWarnings({ "unchecked" }) public void shouldJSONize() { JSONObject key1 = new JSONObject(); key1.put("notAttr", "pub1:double"); key1.put("subscriptionAttr", "sub1:double"); JSONObject json = new JSONObject(); json.put(key1.toJSONString(), 10.0D); assertThat(function.toJSONString()).isEqualTo(json.toJSONString()); assertThat(ContextFunction.fromJSON(json)).isEqualTo(function); }
From source file:edu.anu.spice.Evaluation.java
@SuppressWarnings("unchecked") @Override/*from w w w . ja v a 2s. c o m*/ public String toJSONString() { JSONObject jsonObj = new JSONObject(); jsonObj.put("tp", new Integer(tp)); jsonObj.put("fp", new Integer(fp)); jsonObj.put("fn", new Integer(fn)); jsonObj.put("f", new Double(f)); jsonObj.put("pr", new Double(pr)); jsonObj.put("re", new Double(re)); jsonObj.put("numImages", new Integer(numImages)); return JSONValue.toJSONString(jsonObj); }
From source file:Activities.java
private String addData(String endpoint) { String data = null;/*from w ww . java 2 s . c om*/ try { // Construct request payload JSONObject attrObj = new JSONObject(); attrObj.put("name", "URL"); attrObj.put("value", "http://www.nvidia.com/game-giveaway"); JSONArray attrArray = new JSONArray(); attrArray.add(attrObj); TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); String dateAsISO = df.format(new Date()); // Required attributes JSONObject obj = new JSONObject(); obj.put("leadId", "1001"); obj.put("activityDate", dateAsISO); obj.put("activityTypeId", "1001"); obj.put("primaryAttributeValue", "Game Giveaway"); obj.put("attributes", attrArray); System.out.println(obj); // Make request URL url = new URL(endpoint); HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection(); urlConn.setRequestMethod("POST"); urlConn.setAllowUserInteraction(false); urlConn.setDoOutput(true); urlConn.setRequestProperty("Content-type", "application/json"); urlConn.setRequestProperty("accept", "application/json"); urlConn.connect(); OutputStream os = urlConn.getOutputStream(); os.write(obj.toJSONString().getBytes()); os.close(); // Inspect response int responseCode = urlConn.getResponseCode(); if (responseCode == 200) { System.out.println("Status: 200"); InputStream inStream = urlConn.getInputStream(); data = convertStreamToString(inStream); System.out.println(data); } else { System.out.println(responseCode); data = "Status:" + responseCode; } } catch (MalformedURLException e) { System.out.println("URL not valid."); } catch (IOException e) { System.out.println("IOException: " + e.getMessage()); e.printStackTrace(); } return data; }
From source file:biomine.bmvis2.pipeline.EdgeGoodnessHider.java
public JSONObject toJSON() { JSONObject ret = new JSONObject(); ret.put("limit", limit); return ret; }
From source file:co.mcme.animations.triggers.PlayerChatTrigger.java
@Override public JSONObject toJSON() { JSONObject result = new JSONObject(); JSONObject data = new JSONObject(); data.put("frame", frame); data.put("message", message); data.put("distance", radius); result.put("player_chat", data); return result; }
From source file:de.hstsoft.sdeep.model.Note.java
@SuppressWarnings("unchecked") public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); jsonObject.put("x", (float) position.getX()); jsonObject.put("y", (float) position.getY()); jsonObject.put("title", title); jsonObject.put("text", text); jsonObject.put("year", year); jsonObject.put("month", month); jsonObject.put("day", day); jsonObject.put("daysSurvived", daysSurvived); return jsonObject; }