List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:model.Post_store.java
public static int getlastid() { JSONParser parser = new JSONParser(); int lastid = 1; try {/*from w w w . ja v a 2 s . c o m*/ Object idObj = parser.parse(new FileReader(root + "posts/lastid.json")); JSONObject jsonObject = (JSONObject) idObj; String slastid = jsonObject.get("lastid").toString(); lastid = Integer.parseInt(slastid); //System.out.println(lastid); } catch (FileNotFoundException e) { JSONObject newIdObj = new JSONObject(); lastid = 1; newIdObj.put("lastid", lastid); try (FileWriter file = new FileWriter(root + "posts/lastid.json");) { file.write(newIdObj.toJSONString()); file.flush(); file.close(); } catch (IOException ex) { System.out.println(e); } } catch (IOException e) { System.out.println(e); } catch (ParseException e) { System.out.println(e); } return lastid; }
From source file:net.duckling.ddl.web.api.pan.APIPanOperateController.java
@SuppressWarnings({ "unchecked", "deprecation" }) private static void writeResponse(HttpServletResponse response, int state, String message) { JSONObject msg = new JSONObject(); boolean r = state == 0 ? true : false; msg.put("result", r); msg.put("message", message); JsonUtil.writeJSONObject(response, msg); }
From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java
@SuppressWarnings("unchecked") public static JSONArray serializeAnnotations(List<Annotation> annotations) throws IOException { JSONArray jsonArray = new JSONArray(); if (annotations != null) { for (Annotation annotation : annotations) { JSONObject jsonObj = new JSONObject(); jsonObj.put(KEY_ID, annotation.getId()); jsonObj.put(KEY_PARENT_ID, annotation.getParentId()); jsonObj.put(KEY_ROOT_ID, annotation.getRootId()); jsonObj.put(KEY_OBJECT_URI, annotation.getObjectUri()); jsonObj.put(KEY_CREATED, annotation.getCreated().getTime()); jsonObj.put(KEY_LAST_MODIFIED, annotation.getLastModified().getTime()); jsonObj.put(KEY_CREATED_BY, serializeUser(annotation.getCreatedBy())); jsonObj.put(KEY_TITLE, annotation.getTitle()); jsonObj.put(KEY_TEXT, annotation.getText()); jsonObj.put(KEY_MEDIA_TYPE, annotation.getMediaType().name()); if (annotation.getMediaType() == MediaType.IMAGE || annotation.getMediaType() == MediaType.MAP) { ImageAnnotation i = (ImageAnnotation) annotation; if (i.hasFragment()) { SVGFragmentHandler svg = new SVGFragmentHandler(); jsonObj.put("fragment", svg.toSVG((ImageFragment) i.getFragment())); }//from w ww. j av a 2 s. c o m } else if (annotation.getMediaType() == MediaType.AUDIO) { AudioAnnotation a = (AudioAnnotation) annotation; if (a.hasFragment()) { AudioFragmentHandler afh = new AudioFragmentHandler(); jsonObj.put("fragment", afh.serializeAudioFragment((AudioFragment) a.getFragment())); } } jsonObj.put(KEY_SCOPE, annotation.getScope().name()); if (annotation.hasTags()) jsonObj.put(KEY_TAGS, serializeSemanticTags(annotation.getTags())); if (annotation.hasReplies()) jsonObj.put(KEY_REPLIES, serializeAnnotations(annotation.getReplies())); jsonArray.add(jsonObj); } } return jsonArray; }
From source file:fr.zcraft.zlib.components.rawtext.RawText.java
static public JSONObject toJSON(Entity entity) { JSONObject obj = new JSONObject(); String name = entity.getCustomName(); if (name == null || name.isEmpty()) name = entity.getName();// w w w . jav a 2 s. co m obj.put("name", name); obj.put("type", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, entity.getType().toString())); obj.put("id", entity.getUniqueId().toString()); return obj; }
From source file:it.polimi.logging.LogMessageUtils.java
public static JSONObject buildStatus(int proxSubCount, int groupSubCount, int geoSubCount) { JSONObject status = new JSONObject(); status.put(JsonStrings.PROX_SUB_COUNT, proxSubCount); status.put(JsonStrings.GROUP_SUB_COUNT, groupSubCount); status.put(JsonStrings.GEO_SUB_COUNT, geoSubCount); return status; }
From source file:com.aerothai.database.accessory.AccessoryService.java
/** * Method to construct JSON with Error Msg * * @param tag// www .j a v a 2 s .c o m * @param status * @param err_msg * @return */ public static String constructJSON(String tag, boolean status, String msg) { JSONObject obj = new JSONObject(); obj.put("tag", tag); obj.put("status", new Boolean(status)); obj.put("msg", msg); return obj.toString(); }
From source file:it.polimi.logging.LogMessageUtils.java
/** * //from w w w . j ava 2 s .c om * Costruisce un messaggio di log rappresentante un evento scatenato in seguito ad un * messaggio ricevuto * * @param id * @param sender * @param type * @param logType * @param eventType * @param status * @param timestamp * @return */ public static String buildEventLog(String id, String sender, Type type, String eventType, JSONObject status, long timestamp) { JSONObject msg = new JSONObject(); msg.put(JsonStrings.LOG_ID, id); msg.put(JsonStrings.SENDER, sender); msg.put(JsonStrings.ENTITY_TYPE, type.name()); msg.put(JsonStrings.LOG_TYPE, LogType.EVENT.name()); msg.put(JsonStrings.EVENT_TYPE, eventType); msg.put(JsonStrings.STATUS, status); msg.put(JsonStrings.TIMESTAMP, timestamp); return msg.toJSONString(); }
From source file:it.polimi.logging.LogMessageUtils.java
/** * //from www . j a va2 s . c o m * Costruisce un messaggio di log rappresentante un messaggio ricevuto da un device * * @param id * @param sender * @param type * @param logType * @param eventType * @param timestamp * @return */ public static String buildMessageReceivedLog(String id, String sender, Type type, MessageType eventType, String topic_reply, JSONObject status, long timestamp) { JSONObject msg = new JSONObject(); msg.put(JsonStrings.LOG_ID, id); msg.put(JsonStrings.SENDER, sender); msg.put(JsonStrings.ENTITY_TYPE, type.name()); msg.put(JsonStrings.LOG_TYPE, LogType.REC_MSG.name()); msg.put(JsonStrings.EVENT_TYPE, eventType.name()); if (eventType.equals(MessageType.SYNC_RESP)) msg.put(JsonStrings.TOPIC_REPLY, topic_reply); msg.put(JsonStrings.STATUS, status); msg.put(JsonStrings.TIMESTAMP, timestamp); return msg.toJSONString(); }
From source file:it.polimi.logging.LogMessageUtils.java
/** * //from ww w . j av a 2 s .c o m * Costruisce un messaggio di log per rappresentare i messaggi inviati sulla rete da un device * * @param id * @param sender * @param type * @param logType * @param eventType - rappresenta l'evento che verr eventualmente scatenato, quindi il {@link MessageType} * @param valid - ha senso solo per i messaggi di tipo {@link MessageType#CHECK_OUT} * @param timestamp * @return */ public static String buildMessageSentLog(String id, String sender, Type type, MessageType eventType, String topic_reply, boolean valid, long timestamp) { JSONObject msg = new JSONObject(); msg.put(JsonStrings.LOG_ID, id); msg.put(JsonStrings.SENDER, sender); msg.put(JsonStrings.ENTITY_TYPE, type.name()); msg.put(JsonStrings.LOG_TYPE, LogType.SENT_MSG.name()); msg.put(JsonStrings.EVENT_TYPE, eventType.name()); if (eventType.equals(MessageType.SYNC_REQ)) msg.put(JsonStrings.TOPIC_REPLY, topic_reply); if (eventType.equals(MessageType.CHECK_OUT)) msg.put(JsonStrings.VALID, valid); msg.put(JsonStrings.TIMESTAMP, timestamp); return msg.toJSONString(); }
From source file:com.cbmapi.CbmAPI.java
private static String convertArrayToJsonString(String[] infoArray) { //Depending on prefered formating, use of temp is not necessary. JSONObject temp = new JSONObject(); JSONObject jObj = new JSONObject(); int length = infoArray.length; for (int i = 1; i < length - 1; i += 2) { int y = i + 1; temp.put(infoArray[i].trim(), infoArray[y].trim()); }/*from ww w. j av a 2 s .c om*/ //Name of the cpu is always located first in the array. jObj.put(infoArray[0], temp); return jObj.toString(); }