本文整理汇总了Java中org.json.simple.JSONObject.remove方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.remove方法的具体用法?Java JSONObject.remove怎么用?Java JSONObject.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.simple.JSONObject
的用法示例。
在下文中一共展示了JSONObject.remove方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifyAttachmentJSON
import org.json.simple.JSONObject; //导入方法依赖的package包/类
private static void modifyAttachmentJSON(JSONObject json) {
Long quantityQNT = (Long) json.remove("quantityQNT");
if (quantityQNT != null) {
json.put("quantityQNT", String.valueOf(quantityQNT));
}
Long priceNQT = (Long) json.remove("priceNQT");
if (priceNQT != null) {
json.put("priceNQT", String.valueOf(priceNQT));
}
Long discountNQT = (Long) json.remove("discountNQT");
if (discountNQT != null) {
json.put("discountNQT", String.valueOf(discountNQT));
}
Long refundNQT = (Long) json.remove("refundNQT");
if (refundNQT != null) {
json.put("refundNQT", String.valueOf(refundNQT));
}
}
示例2: createResponse
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* boxインストールが実行されていないか、実行されたがキャッシュの有効期限が切れた場合のレスポンスを作成する.
* @return レスポンス用JSONオブジェクト
*/
@SuppressWarnings("unchecked")
private JSONObject createResponse(JSONObject values) {
JSONObject response = new JSONObject();
response.putAll(values);
response.remove("cell_id");
response.remove("box_id");
response.put("schema", this.getBox().getSchema());
ProgressInfo.STATUS status = ProgressInfo.STATUS.valueOf((String) values.get("status"));
if (status == ProgressInfo.STATUS.COMPLETED) {
response.remove("progress");
String startedAt = (String) response.remove("started_at");
response.put("installed_at", startedAt);
}
response.put("status", status.value());
return response;
}
示例3: showThreatExceptionRulebase
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
*This function returns all the threat exception rules of a given rule and given threat layer .
*
* @param threatLayer the threat layer of the threat rule
* @param ruleUid the rule uid of the rule containing the exception rules
*
* @return the exception rules, or null in case of fail.
*/
private static JSONObject showThreatExceptionRulebase(Layer threatLayer, String ruleUid) {
ApiResponse res;
//Creating the payload
JSONObject payload = new JSONObject();
payload.put("rule-uid", ruleUid);
payload.put("details-level", "full");
payload.put("use-object-dictionary",true);
payload.put("uid", threatLayer.getUid());
try {
configuration.getLogger().debug("Run command: 'show-threat-rule-exception-rulebase' " +
"for threat layer: '" + threatLayer.getName() + "' ('" + ruleUid
+ "') with details level 'full'");
res = client.apiCall(loginResponse,"show-threat-rule-exception-rulebase", payload);
}
catch (ApiClientException e) {
// probably due to a version that does not support threatLayerUid and supports only layerName
payload.remove("uid");
payload.put("name", threatLayer.getName());
try {
res = client.apiCall(loginResponse,"show-threat-rule-exception-rulebase", payload);
}
catch (ApiClientException e1) {
handleException(e1,"Failed to run show-threat-rule-exception-rulebase command ("
+ threatLayer.getName() + "'" + threatLayer.getUid() + "')");
return null;
}
}
if (res == null || !res.isSuccess()) {
configuration.getLogger().severe("Failed to run show-threat-rule-exception-rulebase command ('"
+ threatLayer.getName() + "' uid: '" + threatLayer.getUid() + "'). " +
errorResponseToString(res));
return null;
}
return res.getPayload();
}
示例4: setSubjectPath
import org.json.simple.JSONObject; //导入方法依赖的package包/类
protected static void setSubjectPath(String subject, String path){
boolean portable=ClassicRoutines.isPortable();
// If subject folders key doesn't exist, it is created
if(!jsonConf.containsKey("SubjectFolders")) jsonConf.put("SubjectFolders", new JSONObject()); // Not portable
if(!jsonConf.containsKey("RelativeSubjectFolders")) jsonConf.put("RelativeSubjectFolders", new JSONObject()); // Portable
JSONObject jsonfoldersabs=(JSONObject) jsonConf.get("SubjectFolders");
JSONObject jsonfoldersrel=(JSONObject) jsonConf.get("RelativeSubjectFolders");
String subjectUniqueName=getSubjectUniqueName(subject);
// If the subject folder is registered, it is deleted so as to add it again
if(jsonfoldersabs.containsKey(subjectUniqueName)) jsonfoldersabs.remove(subjectUniqueName);
if(jsonfoldersrel.containsKey(subjectUniqueName)) jsonfoldersrel.remove(subjectUniqueName);
String relpath=ClassicRoutines.getRelativePath(path, ClassicRoutines.getJarPathFolder());
if(path.equals(relpath) || !portable){
// Save it as absolute if equal or not portable
jsonfoldersabs.put(subjectUniqueName, path);
} else{
// Save it as relative
jsonfoldersrel.put(subjectUniqueName,relpath);
}
// Update the SubjectFolders section
if(jsonConf.containsKey("SubjectFolders")) jsonConf.remove("SubjectFolders");
jsonConf.put("SubjectFolders", jsonfoldersabs);
if(jsonConf.containsKey("RelativeSubjectFolders")) jsonConf.remove("RelativeSubjectFolders");
jsonConf.put("RelativeSubjectFolders", jsonfoldersrel);
}
示例5: getActivitySummary
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public static Map<String, Object> getActivitySummary(JSONObject activitySummary, String activityType)
{
Map<String, Object> summary = new HashMap<String, Object>();
if(activityType.equals("org.alfresco.documentlibrary.file-added"))
{
String nodeRefStr = (String)activitySummary.remove("nodeRef");
if(NodeRef.isNodeRef(nodeRefStr))
{
summary.put("objectId", new NodeRef(nodeRefStr).getId());
}
else
{
throw new RuntimeException("nodeRef " + nodeRefStr + " in activity feed is not a valid NodeRef");
}
String parentNodeRefStr = (String)activitySummary.remove("parentNodeRef");
if(NodeRef.isNodeRef(parentNodeRefStr))
{
summary.put("parentObjectId", new NodeRef(parentNodeRefStr).getId());
}
else
{
throw new RuntimeException("parentNodeRef " + parentNodeRefStr + " in activity feed is not a valid NodeRef");
}
summary.put("lastName", activitySummary.get("lastName"));
summary.put("firstName", activitySummary.get("firstName"));
summary.put("title", activitySummary.get("title"));
} else if(activityType.equals("org.alfresco.site.user-joined"))
{
summary.put("lastName", activitySummary.get("lastName"));
summary.put("firstName", activitySummary.get("firstName"));
summary.put("memberLastName", activitySummary.get("memberLastName"));
summary.put("memberFirstName", activitySummary.get("memberFirstName"));
summary.put("memberPersonId", activitySummary.get("memberUserName"));
summary.put("role", activitySummary.get("role"));
summary.put("title", activitySummary.get("title"));
}
return summary;
}
示例6: TestEventResource
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* リクエストボディのlevelがない場合に場合にエラーとなること.
*/
@Test(expected = PersoniumCoreException.class)
public void リクエストボディのlevelがない場合にエラーとなること() {
TestEventResource resource = new TestEventResource();
JSONObject body = createEventBody();
body.remove("level");
StringReader reader = new StringReader(body.toJSONString());
JSONEvent event = resource.getRequestBody(reader);
resource.validateEventProperties(event);
}
示例7: Node
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* Creates a new {@code Node} that corresponds to the given JSONObject.
*
* @param node JSONObject describing the node.
*/
Node(JSONObject node) {
this.properties = node;
// Children
Object childrenValue = node.get("children"); // NOI18N
if (childrenValue != null) {
initChildren();
JSONArray childrenArray = (JSONArray)childrenValue;
List<Node> newChildren = new ArrayList<Node>(childrenArray.size());
for (Object child : childrenArray) {
newChildren.add(new Node((JSONObject)child));
}
addChildren(newChildren);
}
Object shadowRootsValue = node.get("shadowRoots"); // NOI18N
if (shadowRootsValue instanceof JSONArray) {
JSONArray shadowRootArray = (JSONArray)shadowRootsValue;
for (Object shadowRoot : shadowRootArray) {
addShadowRoot(new Node((JSONObject)shadowRoot));
}
}
// Attributes
JSONArray array = (JSONArray)getProperties().get("attributes"); // NOI18N
if (array != null) {
for (int i=0; i<array.size()/2; i++) {
String name = (String)array.get(2*i);
String value = (String)array.get(2*i+1);
setAttribute(name, value);
}
}
// Content document
JSONObject document = (JSONObject)getProperties().get("contentDocument"); // NOI18N
if (document != null) {
contentDocument = new Node(document);
contentDocument.parent = this;
// A node cannot have both children and content document.
// FRAME doesn't support children at all and children
// of IFRAME are interpreted when frames are not supported
// only (i.e. when the content document is null)
// => no need to ask for children of a node with a content
// document. We can set children to empty collection immediately.
initChildren();
}
// Cleanup
node.remove("children"); // NOI18N
node.remove("attributes"); // NOI18N
node.remove("contentDocument"); // NOI18N
}
示例8: getData
import org.json.simple.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
/**
* Connects to the server and downloads information as specified in the GUI.
* Will block until data is received but can be stopped by pressing the
* back (escape) button. Throws various Exceptions if errors occur such as not
* being able to connect to the server.
*
* @return A Map containing all information specified by the professors.
* @throws IOException
* If there is an error communicating with the server.
* @throws UnknownHostException
* If the server cannot be found.
* @throws ParseException
* If an error occurs in parsing data from the server.
* @see java.util.Map
*/
public Map getData() throws IOException, UnknownHostException, ParseException {
if (this.debugPrint)
System.out.println("Connecting...");
// Connect to server, set timeout
Socket conn = new Socket(serverIP, portNumber);
conn.setSoTimeout(timeout);
// Create a thread to monitor the escape (back) button in case user
// wants to exit
Thread buttonChk = new Thread(new exitButtonChecker(this.debugPrint, conn));
buttonChk.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
PrintWriter writer = new PrintWriter(conn.getOutputStream(), true);
if (this.debugPrint)
System.out.println("Connected. Sending request.");
// Create data to send to server
JSONObject obj = new JSONObject();
obj.put("Type", "REQ");
obj.put("Team Number", new Integer(this.teamNumber));
// Send data to server
writer.println(obj.toJSONString());
if (this.debugPrint)
System.out.println("Request sent; waiting for response");
// Wait for and read response from server
String response = reader.readLine();
// Process response from server
JSONObject rJSONObject = (JSONObject) JSONValue.parse(response);
if (!rJSONObject.containsKey("Type") || !rJSONObject.get("Type").equals("RESP")
|| !rJSONObject.containsKey("Status")) {
throw new IOException("Corrupted data received");
} else if (rJSONObject.containsKey("Status") && !rJSONObject.get("Status").equals("OK")) {
throw new IOException("Bad server status: " + rJSONObject.get("Status"));
} else if (this.debugPrint) {
System.out.println("Response received OK.");
}
// Remove type and status as they are not needed by the user
rJSONObject.remove("Type");
rJSONObject.remove("Status");
// Clean up: close connection, terminate button watch thread, return
// data to caller
conn.close();
buttonChk.interrupt();
return rJSONObject;
}
示例9: JSONObject
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* BoxとRelationのLink削除時に単一キーの同名Relationが存在すると409になること.
*/
@Test
@SuppressWarnings("unchecked")
public final void BoxとRelationのLink削除時に単一キーの同名Relationが存在すると409になること() {
final String boxName = "relationLinkBox";
final String relationName = "boxLinkRelation";
try {
// Boxの作成
BoxUtils.create(CELL_NAME, boxName, TOKEN, HttpStatus.SC_CREATED);
// 上のBoxと結びつくRelation作成
JSONObject body = new JSONObject();
body.put("Name", relationName);
body.put("_Box.Name", boxName);
RelationUtils.create(CELL_NAME, TOKEN, body, HttpStatus.SC_CREATED);
// 上のBoxと結びつかないRelation作成
body.remove("_Box.Name");
RelationUtils.create(CELL_NAME, TOKEN, body, HttpStatus.SC_CREATED);
String relationKeyName = "_Box.Name='" + boxName + "',Name='" + relationName + "'";
// BoxとRelationのLink削除(単一キーのRelationが存在するため削除できない(409))
deleteBoxRelationLink(boxName, relationKeyName, HttpStatus.SC_CONFLICT);
// RelationとBoxのLink削除(逆向きでも同様に409)
deleteRelationBoxLink(relationKeyName, boxName, HttpStatus.SC_CONFLICT);
// Relationの削除
RelationUtils.delete(CELL_NAME, TOKEN, relationName, null, HttpStatus.SC_NO_CONTENT);
// BoxとRelationのLink削除(単一キーのRelationが存在しないので削除できる)
deleteBoxRelationLink(boxName, relationKeyName, HttpStatus.SC_NO_CONTENT);
// 結びつくRelationの削除
RelationUtils.delete(CELL_NAME, TOKEN, relationName, null, HttpStatus.SC_NO_CONTENT);
// Boxの削除
BoxUtils.delete(CELL_NAME, TOKEN, boxName, HttpStatus.SC_NO_CONTENT);
} finally {
// 結びつくRelationの削除
RelationUtils.delete(CELL_NAME, TOKEN, relationName, boxName, -1);
RelationUtils.delete(CELL_NAME, TOKEN, relationName, null, -1);
// Boxの削除
BoxUtils.delete(CELL_NAME, TOKEN, boxName, -1);
}
}
示例10: tick
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* Called every tick
*/
public void tick() {
JSONObject json = new JSONObject();
json.put("t", "tick");
LogManager.LOGGER.info("Notified " + userManager.getOnlineUsers().size() + " users");
ArrayList<OnlineUser> onlineUsers = new ArrayList<>(userManager.getOnlineUsers()); //Avoid ConcurrentModificationException
for (OnlineUser user : onlineUsers) {
if (user.getWebSocket().isOpen()) {
if (user.isGuest()) {
json.remove("c");
user.getWebSocket().send(json.toJSONString());
} else {
try {
ControllableUnit unit = user.getUser().getControlledUnit();
//Send keyboard updated buffer
ArrayList<Integer> kbBuffer = unit.getKeyboardBuffer();
JSONArray keys = new JSONArray();
keys.addAll(kbBuffer);
json.put("keys", keys);
//Send console buffer
if (unit.getConsoleMessagesBuffer().size() > 0) {
JSONArray buff = new JSONArray();
for (char[] message : unit.getConsoleMessagesBuffer()) {
buff.add(new String(message));
}
json.put("c", buff);
} else {
json.remove("c");
}
json.put("cm", unit.getConsoleMode());
//Send tick message
user.getWebSocket().send(json.toJSONString());
} catch (NullPointerException e) {
//User is online but not completely initialised
}
}
}
}
}