org.codehaus.jettison.json.JSONObject.remove()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.codehaus.jettison.json.JSONObject.remove()方法的一些代码示例,展示了JSONObject.remove()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.remove()方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:remove

JSONObject.remove介绍

[英]Remove a name and its value, if present.
[中]删除名称及其值(如果存在)。

代码示例

代码示例来源:origin: json-path/JsonPath

@Override
public void removeProperty(Object obj, Object key)
{
  try
  {
    if( obj instanceof org.codehaus.jettison.json.JSONArray )
    {
      int index = key instanceof Integer? (Integer) key : Integer.parseInt(key.toString());
      if( index<length(obj) )
      {
        Object temp = new Object(); // Need FIX: JSONArray.remove(int)
        ((org.codehaus.jettison.json.JSONArray)obj).put(index, temp);
        ((org.codehaus.jettison.json.JSONArray)obj).remove(temp);
      }
    }
    if( obj instanceof org.codehaus.jettison.json.JSONObject )
    {
      ((org.codehaus.jettison.json.JSONObject)obj).remove(String.valueOf(key));
    }
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new IllegalStateException(jsonException);
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

@Override
public void removeProperty(Object obj, Object key)
{
  try
  {
    if( obj instanceof org.codehaus.jettison.json.JSONArray )
    {
      int index = key instanceof Integer? (Integer) key : Integer.parseInt(key.toString());
      if( index<length(obj) )
      {
        Object temp = new Object(); // Need FIX: JSONArray.remove(int)
        ((org.codehaus.jettison.json.JSONArray)obj).put(index, temp);
        ((org.codehaus.jettison.json.JSONArray)obj).remove(temp);
      }
    }
    if( obj instanceof org.codehaus.jettison.json.JSONObject )
    {
      ((org.codehaus.jettison.json.JSONObject)obj).remove(String.valueOf(key));
    }
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new IllegalStateException(jsonException);
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

this.myHashMap.put(key, null);
} else {
  remove(key);

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

private void clearArrayItems() {
    
    object.remove("items");
    this.arrayItems = null;
  }
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

private void clearProperties() {
  object.remove("properties");
  this.properties=null;
}

代码示例来源:origin: com.github.lafa.jsonpath/json-path

@Override
public void removeProperty(Object obj, Object key)
{
  try
  {
    if( obj instanceof org.codehaus.jettison.json.JSONArray )
    {
      int index = key instanceof Integer? (Integer) key : Integer.parseInt(key.toString());
      if( index<length(obj) )
      {
        Object temp = new Object(); // Need FIX: JSONArray.remove(int)
        ((org.codehaus.jettison.json.JSONArray)obj).put(index, temp);
        ((org.codehaus.jettison.json.JSONArray)obj).remove(temp);
      }
    }
    if( obj instanceof org.codehaus.jettison.json.JSONObject )
    {
      ((org.codehaus.jettison.json.JSONObject)obj).remove(String.valueOf(key));
    }
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new IllegalStateException(jsonException);
  }
}

代码示例来源:origin: org.codehaus.jettison/com.springsource.org.codehaus.jettison

/**
 * Put a key/value pair in the JSONObject. If the value is null,
 * then the key will be removed from the JSONObject if it is present.
 * @param key   A key string.
 * @param value An object which is the value. It should be of one of these
 *  types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
 *  or the JSONObject.NULL object.
 * @return this.
 * @throws JSONException If the value is non-finite number
 *  or if the key is null.
 */
public JSONObject put(String key, Object value) throws JSONException {
  if (key == null) {
    throw new JSONException("Null key.");
  }
  if (value != null) {
    testValidity(value);
    this.myHashMap.put(key, value);
  } else {
    remove(key);
  }
  return this;
}

代码示例来源:origin: org.apache.apex/malhar-library

@Override
public String getSchemaJSON()
{
 if (!changed && schemaJSON != null) {
  return schemaJSON;
 }
 if (schemaKeys == null) {
  schema.remove(Schema.FIELD_SCHEMA_KEYS);
 } else {
  try {
   schema.put(Schema.FIELD_SCHEMA_KEYS, SchemaUtils.createJSONObject(schemaKeys));
  } catch (JSONException ex) {
   throw new RuntimeException(ex);
  }
 }
 schemaJSON = schema.toString();
 return schemaJSON;
}

代码示例来源:origin: thinkaurelius/faunus

public static FaunusVertex fromJSON(String line) throws IOException {
  try {
    final JSONObject json = new JSONObject(new JSONTokener(line));
    line = EMPTY_STRING; // clear up some memory
    final FaunusVertex vertex = (FaunusVertex) graphson.vertexFromJson(json);
    fromJSONEdges(vertex, json.optJSONArray(_OUT_E), OUT);
    json.remove(_OUT_E); // clear up some memory
    fromJSONEdges(vertex, json.optJSONArray(_IN_E), IN);
    json.remove(_IN_E); // clear up some memory
    return vertex;
  } catch (Exception e) {
    throw new IOException(e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.slider/slider-core

private void readConfigEntries(JSONObject inpConfig,
                File clientInstallPath,
                JSONObject globalConfig,
                String name, String user)
  throws JSONException {
 JSONObject globalSection = inpConfig.getJSONObject("global");
 Iterator it = globalSection.keys();
 while (it.hasNext()) {
  String key = (String) it.next();
  String value = globalSection.getString(key);
  if (SliderUtils.isSet(value)) {
   value = value.replace("{app_install_dir}", clientInstallPath.getAbsolutePath());
   value = value.replace("{app_user}", user);
   if (name != null) {
    value = value.replace("{app_name}", name);
   }
  }
  if (globalConfig.has(key)) {
   // last one wins
   globalConfig.remove(key);
  }
  globalConfig.put(key, value);
 }
}

代码示例来源:origin: apache/incubator-slider

private void readConfigEntries(JSONObject inpConfig,
                File clientInstallPath,
                JSONObject globalConfig,
                String name, String user)
  throws JSONException {
 JSONObject globalSection = inpConfig.getJSONObject("global");
 Iterator it = globalSection.keys();
 while (it.hasNext()) {
  String key = (String) it.next();
  String value = globalSection.getString(key);
  if (SliderUtils.isSet(value)) {
   value = value.replace("{app_install_dir}", clientInstallPath.getAbsolutePath());
   value = value.replace("{app_user}", user);
   if (name != null) {
    value = value.replace("{app_name}", name);
   }
  }
  if (globalConfig.has(key)) {
   // last one wins
   globalConfig.remove(key);
  }
  globalConfig.put(key, value);
 }
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

/**
 * <p>removeProperty.</p>
 *
 * @param property a {@link JsonSchemaNode} object.
 */
public void removeProperty(JsonSchemaNode property){
  
  JSONObject propertiesObject = null;
  try {
    propertiesObject = object.getJSONObject("properties");			
  } catch (JSONException e) {
  }
  if(propertiesObject==null)
    return;
  
  propertiesObject.remove(property.getName());
  if(properties!=null)
    properties.remove(property.getName());
  
  fireChanges();
}

代码示例来源:origin: org.apache.apex/apex-engine

@Override
 public void execute(String[] args, ConsoleReader reader) throws Exception
 {
  String[] tmpArgs = new String[args.length - 2];
  System.arraycopy(args, 2, tmpArgs, 0, args.length - 2);
  GetAppPackageInfoCommandLineInfo commandLineInfo = getGetAppPackageInfoCommandLineInfo(tmpArgs);
  try (AppPackage ap = newAppPackageInstance(new URI(args[1]), true)) {
   JSONSerializationProvider jomp = new JSONSerializationProvider();
   jomp.addSerializer(PropertyInfo.class,
     new AppPackage.PropertyInfoSerializer(commandLineInfo.provideDescription));
   JSONObject apInfo = new JSONObject(jomp.getContext(null).writeValueAsString(ap));
   apInfo.remove("name");
   printJson(apInfo);
  }
 }
}

代码示例来源:origin: org.apache.apex/malhar-library

schema.remove(Schema.FIELD_SCHEMA_KEYS);
} else {
 try {
 time.remove(FIELD_TIME_FROM);
 time.remove(FIELD_TIME_TO);
} else {
 try {
  keyData.remove(DimensionalConfigurationSchema.FIELD_KEYS_ENUMVALUES);
  continue;

代码示例来源:origin: ORCID/ORCID-Source

private void updateOpportunityInSalesForce(String accessToken, Opportunity opportunity) {
  LOGGER.info("About to flag opportunity as closed in SalesForce");
  WebResource resource = createObjectsResource("/Opportunity/", opportunity.getId()).queryParam("_HttpMethod", "PATCH");
  JSONObject memberJson = salesForceAdapter.createSaleForceRecordFromOpportunity(opportunity);
  // SalesForce doesn't allow the Id in the body
  memberJson.remove("Id");
  ClientResponse response = doPostRequest(resource, memberJson, accessToken);
  checkAuthorization(response);
  checkResponse(response, 204, "Error updating opportunity in SalesForce");
}

代码示例来源:origin: ORCID/ORCID-Source

private void updateContactInSalesForce(String accessToken, Contact contact) {
  LOGGER.info("About update contact in SalesForce");
  String contactId = contact.getId();
  validateSalesForceId(contactId);
  WebResource resource = createObjectsResource("/Contact/", contactId).queryParam("_HttpMethod", "PATCH");
  JSONObject contactJson = salesForceAdapter.createSaleForceRecordFromContact(contact);
  // SalesForce doesn't allow the Id in the body
  contactJson.remove("Id");
  ClientResponse response = doPostRequest(resource, contactJson, accessToken);
  checkAuthorization(response);
  checkResponse(response, 204, "Error updating contact in SalesForce");
  return;
}

代码示例来源:origin: ORCID/ORCID-Source

private void updateContactRoleInSalesForce(String accessToken, ContactRole contactRole) {
  LOGGER.info("About update contact role in SalesForce");
  String contactRoleId = contactRole.getId();
  validateSalesForceId(contactRoleId);
  WebResource resource = createObjectsResource("/Membership_Contact_Role__C/", contactRoleId).queryParam("_HttpMethod", "PATCH");
  JSONObject contactRoleJson = salesForceAdapter.createSaleForceRecordFromContactRole(contactRole);
  // SalesForce doesn't allow the Id in the body
  contactRoleJson.remove("Id");
  ClientResponse response = doPostRequest(resource, contactRoleJson, accessToken);
  checkAuthorization(response);
  checkResponse(response, 204, "Error updating contact role in SalesForce");
  return;
}

代码示例来源:origin: ORCID/ORCID-Source

private void updateMemberInSalesForce(String accessToken, Member member) {
  LOGGER.info("About update member in SalesForce");
  String accountId = member.getId();
  validateSalesForceId(accountId);
  WebResource resource = createObjectsResource("/Account/", accountId).queryParam("_HttpMethod", "PATCH");
  JSONObject memberJson = salesForceAdapter.createSaleForceRecordFromMember(member);
  // SalesForce doesn't allow the Id in the body
  memberJson.remove("Id");
  ClientResponse response = doPostRequest(resource, memberJson, accessToken);
  checkAuthorization(response);
  checkResponse(response, 204, "Error updating member in SalesForce");
  return;
}

代码示例来源:origin: thinkaurelius/faunus

public static JSONObject toJSON(final Vertex vertex) throws IOException {
  try {
    final JSONObject object = GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
    // force the ID to long.  with blueprints, most implementations will send back a long, but
    // some like TinkerGraph will return a string.  the same is done for edges below
    object.put(GraphSONTokens._ID, Long.valueOf(object.remove(GraphSONTokens._ID).toString()));
    List<Edge> edges = (List<Edge>) vertex.getEdges(OUT);
    if (!edges.isEmpty()) {
      final JSONArray outEdgesArray = new JSONArray();
      for (final Edge outEdge : edges) {
        final JSONObject edgeObject = GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
        outEdgesArray.put(edgeObject);
      }
      object.put(_OUT_E, outEdgesArray);
    }
    edges = (List<Edge>) vertex.getEdges(IN);
    if (!edges.isEmpty()) {
      final JSONArray inEdgesArray = new JSONArray();
      for (final Edge inEdge : edges) {
        final JSONObject edgeObject = GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
        inEdgesArray.put(edgeObject);
      }
      object.put(_IN_E, inEdgesArray);
    }
    return object;
  } catch (JSONException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: GluuFederation/oxAuth

if (jsonObj.has(RegisterResponseParam.CLIENT_ID.toString())) {
  setClientId(jsonObj.getString(RegisterResponseParam.CLIENT_ID.toString()));
  jsonObj.remove(RegisterResponseParam.CLIENT_ID.toString());
  jsonObj.remove(CLIENT_SECRET.toString());
  jsonObj.remove(RegisterResponseParam.REGISTRATION_ACCESS_TOKEN.toString());
  jsonObj.remove(REGISTRATION_CLIENT_URI.toString());
    setClientIdIssuedAt(new Date(clientIdIssuedAt * 1000L));
  jsonObj.remove(CLIENT_ID_ISSUED_AT.toString());
    setClientSecretExpiresAt(new Date(clientSecretExpiresAt * 1000L));
  jsonObj.remove(CLIENT_SECRET_EXPIRES_AT.toString());

相关文章