本文整理了Java中org.json.JSONObject.remove()
方法的一些代码示例,展示了JSONObject.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.remove()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:remove
[英]Removes the named mapping if it exists; does nothing otherwise.
[中]删除命名映射(如果存在);否则什么也不做。
代码示例来源:origin: apache/geode
public Object remove(String key) {
return jsonObject.remove(key);
}
代码示例来源:origin: loklak/loklak_server
/**
* Remove the signature
* @param obj the JSONObject
*/
public static void removeSignature(JSONObject obj){
if(obj.has(signatureString)) obj.remove(signatureString);
}
代码示例来源:origin: loklak/loklak_server
@Override
public synchronized Object remove(String key) {
super.remove(key);
commit();
return this;
}
}
代码示例来源:origin: loklak/loklak_server
public static JSONObject user2json(User user) throws IOException {
String jsonstring = TwitterObjectFactory.getRawJSON(user);
JSONObject json = new JSONObject(jsonstring);
json.put("retrieval_date", AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis()));
Object status = json.remove("status"); // we don't need to store the latest status update in the user dump
// TODO: store the latest status in our message database
return json;
}
代码示例来源:origin: alibaba/Tangram-Android
@Override
public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) {
maxChildren = 1;
id = data.optString(KEY_ID, id == null ? "" : id);
this.type = TangramBuilder.TYPE_SINGLE_COLUMN;
this.stringType = TangramBuilder.TYPE_CONTAINER_1C_FLOW;
createCell(this, resolver, data, serviceManager, true);
//do not need parse style, leave style empty
this.extras.remove(KEY_STYLE);
style = new Style();
}
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* 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 NullPointerException("Null key.");
}
if (value != null) {
testValidity(value);
this.map.put(key, value);
} else {
this.remove(key);
}
return this;
}
代码示例来源:origin: loklak/loklak_server
/**
* cleanup deletes all old entries and frees up the memory.
* some outside process muss call this frequently
* @return self
*/
public Accounting cleanup() {
if (!this.has("requests")) return this;
JSONObject requests = this.getJSONObject("requests");
for (String path: requests.keySet()) {
JSONObject events = requests.getJSONObject(path);
// shrink that map and delete everything which is older than now minus one hour
long pivotTime = System.currentTimeMillis() - ONE_HOUR_MILLIS;
while (events.length() > 0 && Long.parseLong(events.keys().next()) < pivotTime) events.remove(events.keys().next());
if (events.length() == 0) requests.remove(path);
}
return this;
}
代码示例来源:origin: json-path/JsonPath
@SuppressWarnings("unchecked")
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
toJsonObject(obj).remove(key.toString());
else {
JSONArray array = toJsonArray(obj);
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
array.remove(index);
}
}
代码示例来源:origin: loklak/loklak_server
/**
* Verfies if the signature of a JSONObject is valid
* @param obj the JSONObject
* @param key the public key of the signature issuer
* @return true if the signature is valid
* @throws SignatureException if the JSONObject does not have a signature or something with the JSONObject is bogus
* @throws InvalidKeyException if the key is not valid (for example not RSA)
*/
public static boolean verify(JSONObject obj, PublicKey key) throws SignatureException, InvalidKeyException {
if(!obj.has(signatureString)) throw new SignatureException("No signature supplied");
Signature signature;
try {
signature = Signature.getInstance("SHA256withRSA");
} catch (NoSuchAlgorithmException e) {
return false; //does not happen
}
String sigString = obj.getString(signatureString);
byte[] sig = Base64.getDecoder().decode(sigString);
obj.remove(signatureString);
signature.initVerify(key);
signature.update(obj.toString().getBytes(StandardCharsets.UTF_8));
boolean res = signature.verify(sig);
obj.put(signatureString, sigString);
return res;
}
代码示例来源:origin: alibaba/Tangram-Android
@Override
public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) {
maxChildren = 1;
this.extras = data;
this.stringType = data.optString(KEY_TYPE);
id = data.optString(KEY_ID, id == null ? "" : id);
loadMore = data.optInt(KEY_LOAD_TYPE, 0) == LOAD_TYPE_LOADMORE;
//you should alway assign hasMore to indicate there's more data explicitly
if (data.has(KEY_HAS_MORE)) {
hasMore = data.optBoolean(KEY_HAS_MORE);
} else {
if (data.has(KEY_LOAD_TYPE)) {
hasMore = data.optInt(KEY_LOAD_TYPE) == LOAD_TYPE_LOADMORE;
}
}
load = data.optString(KEY_API_LOAD, null);
loadParams = data.optJSONObject(KEY_API_LOAD_PARAMS);
loaded = data.optBoolean(KEY_LOADED, false);
createCell(this, resolver, extras, serviceManager, true);
//do not need parse style, leave style empty
this.extras.remove(KEY_STYLE);
style = new Style();
}
代码示例来源:origin: loklak/loklak_server
/**
* 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 NullPointerException("Null key.");
}
if (value != null) {
testValidity(value);
this.map.put(key, value);
} else {
this.remove(key);
}
return this;
}
代码示例来源:origin: loklak/loklak_server
/**
* Remove an object from the internal JSONObject
* @param key the key of the object
*/
public void remove(String key){
this.json.remove(key);
if (this.parent != null && this.credential.isPersistent()) this.parent.commit();
}
代码示例来源:origin: loklak/loklak_server
public static TwitterTimeline peers(final String protocolhostportstub, final String query, final TwitterTimeline.Order order, final String source, final int count, final int timezoneOffset, final String provider_hash) throws IOException {
TwitterTimeline tl = new TwitterTimeline(order);
String urlstring = "";
urlstring = protocolhostportstub + "/api/peers.json";
byte[] response = ClientConnection.download(urlstring);
if (response == null || response.length == 0) return tl;
JSONObject json = new JSONObject(new String(response, StandardCharsets.UTF_8));
JSONArray statuses = json.has("statuses") ? json.getJSONArray("statuses") : null;
if (statuses != null) {
for (Object tweet_obj: statuses) {
JSONObject tweet = (JSONObject) tweet_obj;
JSONObject user = tweet.has("user") ? (JSONObject) tweet.remove("user") : null;
if (user == null) continue;
tweet.put("provider_type", (Object) ProviderType.REMOTE.name());
tweet.put("provider_hash", provider_hash);
UserEntry u = new UserEntry(user);
TwitterTweet t = new TwitterTweet(tweet);
tl.add(t, u);
}
}
//System.out.println(parser.text());
return tl;
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onRemoveSearch(String searchName) {
Timber.d("OnRemoveSelection using search named: %s", searchName);
try {
JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
if (savedFiltersObj != null && savedFiltersObj.has(searchName)) {
savedFiltersObj.remove(searchName);
getCol().getConf().put("savedFilters", savedFiltersObj);
getCol().flush();
if (savedFiltersObj.length() == 0) {
mMySearchesItem.setVisible(false);
}
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: loklak/loklak_server
map.remove("screen_name");
JSONObject names = map.has(setname + "_names") ? (JSONObject) map.remove(setname + "_names") : null;
if (names != null) {
for (String sn: names.keySet()) {
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testJSONObjectWithoutDataAccess() throws JSONException {
AccessToken accessToken = new AccessToken(
"a token",
"1234",
"1000",
Arrays.asList("permission_1", "permission_2"),
Arrays.asList("declined permission_1", "declined permission_2"),
AccessTokenSource.WEB_VIEW,
new Date(2015, 3, 3),
new Date(2015, 1, 1),
new Date(0));
JSONObject jsonObject = accessToken.toJSONObject();
jsonObject.remove("data_access_expiration_time");
AccessToken deserializedAccessToken = AccessToken.createFromJSONObject(jsonObject);
assertEquals(accessToken, deserializedAccessToken);
}
代码示例来源:origin: loklak/loklak_server
public void run() {
JsonFactory tweet;
try {
while ((tweet = dumpReader.take()) != JsonStreamReader.POISON_JSON_MAP) {
try {
JSONObject json = tweet.getJSON();
if (json.remove("user") == null) continue;
TwitterTweet t = new TwitterTweet(json);
String[] mentions = t.getMentions();
if (mentions.length != 1) continue;
boolean pure = t.getImages().size() == 0 && t.getLinks().length == 0 && t.getHashtags().length == 0;
if (!pure) continue;
Map<Long, TwitterTweet> tweets = usertweets.get(t.getScreenName());
if (tweets == null) {
tweets = new TreeMap<>();
usertweets.put(t.getScreenName(), tweets);
}
tweets.put(t.getTimestamp(), t);
tweetcount.incrementAndGet();
} catch (IOException e) {
DAO.severe(e);
}
}
} catch (InterruptedException e) {
DAO.severe(e);
}
}
};
代码示例来源:origin: loklak/loklak_server
JSONObject message = (JSONObject) message_obj;
message.put("screen_name", screenName);
JSONObject user = (JSONObject) message.remove("user");
if (user != null) user.put("screen_name", screenName);
TwitterTweet messageEntry = new TwitterTweet(message);
代码示例来源:origin: loklak/loklak_server
try {
JSONObject json = tweet.getJSON();
JSONObject user = (JSONObject) json.remove("user");
if (user == null) continue;
UserEntry u = new UserEntry(user);
代码示例来源:origin: facebook/facebook-android-sdk
@Suppress
@LargeTest
public void testCommentRoundTrip() throws JSONException {
final AccessToken accessToken = getAccessTokenForSharedUser();
JSONObject status = createStatusUpdate("");
JSONObject createdStatus = batchCreateAndGet(accessToken, "me/feed", status, null);
String statusID = createdStatus.optString("id");
JSONObject comment = new JSONObject();
final String commentMessage = "It truly is a wonderful status update.";
comment.put("message", commentMessage);
JSONObject createdComment1 = batchCreateAndGet(accessToken, statusID + "/comments", comment, null);
assertNotNull(createdComment1);
String comment1ID = createdComment1.optString("id");
String comment1Message = createdComment1.optString("message");
assertNotNull(comment1ID);
assertNotNull(comment1Message);
assertEquals(commentMessage, comment1Message);
// Try posting the same comment to the same status update. We need to clear its ID first.
createdComment1.remove("id");
JSONObject createdComment2 = batchCreateAndGet(accessToken, statusID + "/comments", createdComment1, null);
assertNotNull(createdComment2);
String comment2ID = createdComment2.optString("id");
String comment2Message = createdComment2.optString("message");
assertNotNull(comment2ID);
assertFalse(comment1ID.equals(comment2ID));
assertNotNull(comment2Message);
assertEquals(commentMessage, comment2Message);
}
内容来源于网络,如有侵权,请联系作者删除!