本文整理了Java中org.json.JSONObject.isNull()
方法的一些代码示例,展示了JSONObject.isNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.isNull()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:isNull
[英]Returns true if this object has no mapping for name or if it has a mapping whose value is #NULL.
[中]如果此对象没有名称映射或其值为#NULL的映射,则返回true。
代码示例来源:origin: stackoverflow.com
/** Return the value mapped by the given key, or {@code null} if not present or null. */
public static String optString(JSONObject json, String key)
{
// http://code.google.com/p/android/issues/detail?id=13830
if (json.isNull(key))
return null;
else
return json.optString(key, null);
}
代码示例来源:origin: stackoverflow.com
private String optString_1(final JSONObject json, final String key) {
return json.isNull(key) ? null : json.optString(key);
}
代码示例来源:origin: googlemaps/android-maps-utils
/**
* Parses the properties of a GeoJSON feature into a hashmap
*
* @param properties GeoJSON properties member
* @return hashmap containing property values
* @throws JSONException if the properties could not be parsed
*/
private static HashMap<String, String> parseProperties(JSONObject properties)
throws JSONException {
HashMap<String, String> propertiesMap = new HashMap<String, String>();
Iterator propertyKeys = properties.keys();
while (propertyKeys.hasNext()) {
String key = (String) propertyKeys.next();
propertiesMap.put(key, properties.isNull(key) ? null : properties.getString(key));
}
return propertiesMap;
}
代码示例来源:origin: googlemaps/android-maps-utils
public List<MyItem> read(InputStream inputStream) throws JSONException {
List<MyItem> items = new ArrayList<MyItem>();
String json = new Scanner(inputStream).useDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).next();
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
String title = null;
String snippet = null;
JSONObject object = array.getJSONObject(i);
double lat = object.getDouble("lat");
double lng = object.getDouble("lng");
if (!object.isNull("title")) {
title = object.getString("title");
}
if (!object.isNull("snippet")) {
snippet = object.getString("snippet");
}
items.add(new MyItem(lat, lng, title, snippet));
}
return items;
}
代码示例来源:origin: googlemaps/android-maps-utils
boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
代码示例来源:origin: RipMeApp/ripme
parseJsonChild(children.getJSONObject(j));
if (data.has("after") && !data.isNull("after")) {
String nextURLString = Utils.stripURLParameter(url.toExternalForm(), "after");
if (nextURLString.contains("?")) {
代码示例来源:origin: internetarchive/heritrix3
Frontier frontier, JSONObject params) throws IOException {
boolean includeSuccesses = !params.isNull("includeSuccesses");
boolean includeFailures = !params.isNull("includeFailures");
boolean includeScheduleds = !params.isNull("includeScheduleds");
boolean scopeIncludes = !params.isNull("scopeIncludes");
代码示例来源:origin: internetarchive/heritrix3
int qLines = 0;
boolean scheduleSuccesses = !params.isNull("scheduleSuccesses");
boolean scheduleFailures = !params.isNull("scheduleFailures");
boolean scheduleScheduleds = !params.isNull("scheduleScheduleds");
boolean scopeScheduleds = !params.isNull("scopeScheduleds");
boolean forceRevisit = !params.isNull("forceRevisit");
代码示例来源:origin: internetarchive/heritrix3
boolean forceRevisit = !params.isNull("forceRevisit");
boolean asSeeds = !params.isNull("asSeeds");
boolean scopeScheduleds = !params.isNull("scopeScheduleds");
DecideRule scope = scopeScheduleds ? getScope() : null;
try {
代码示例来源:origin: DV8FromTheWorld/JDA
public static long optLong(JSONObject object, String key, long defaultValue)
{
return object.isNull(key) ? defaultValue : object.getLong(key);
}
}
代码示例来源:origin: DV8FromTheWorld/JDA
public static boolean optBoolean(JSONObject object, String key)
{
return !object.isNull(key) && object.getBoolean(key);
}
代码示例来源:origin: DV8FromTheWorld/JDA
public static int optInt(JSONObject object, String key, int defaultValue)
{
return object.isNull(key) ? defaultValue : object.getInt(key);
}
代码示例来源:origin: DV8FromTheWorld/JDA
private <T> List<T> map(JSONObject jsonObject, String key, Function<JSONObject, T> convert)
{
if (jsonObject.isNull(key))
return Collections.emptyList();
final JSONArray arr = jsonObject.getJSONArray(key);
final List<T> mappedObjects = new ArrayList<>(arr.length());
for (int i = 0; i < arr.length(); i++)
{
JSONObject obj = arr.getJSONObject(i);
mappedObjects.add(convert.apply(obj));
}
return mappedObjects;
}
}
代码示例来源:origin: DV8FromTheWorld/JDA
public static ErrorResponse fromJSON(JSONObject obj)
{
if (obj == null || obj.isNull("code"))
return SERVER_ERROR;
else
{
return ErrorResponse.fromCode(obj.getInt("code"));
}
}
}
代码示例来源:origin: DV8FromTheWorld/JDA
private Member(JSONObject json, Widget widget)
{
this.widget = widget;
this.bot = Helpers.optBoolean(json, "bot");
this.id = json.getLong("id");
this.username = json.getString("username");
this.discriminator = json.getString("discriminator");
this.avatar = json.optString("avatar", null);
this.nickname = json.optString("nick", null);
this.status = OnlineStatus.fromKey(json.getString("status"));
this.game = json.isNull("game") ? null : EntityBuilder.createGame(json.getJSONObject("game"));
}
代码示例来源:origin: DV8FromTheWorld/JDA
public AuditLogChange createAuditLogChange(JSONObject change)
{
final String key = change.getString("key");
Object oldValue = change.isNull("old_value") ? null : change.get("old_value");
Object newValue = change.isNull("new_value") ? null : change.get("new_value");
// Don't confront users with JSON
if (oldValue instanceof JSONArray || newValue instanceof JSONArray)
{
oldValue = oldValue instanceof JSONArray ? ((JSONArray) oldValue).toList() : oldValue;
newValue = newValue instanceof JSONArray ? ((JSONArray) newValue).toList() : newValue;
}
else if (oldValue instanceof JSONObject || newValue instanceof JSONObject)
{
oldValue = oldValue instanceof JSONObject ? ((JSONObject) oldValue).toMap() : oldValue;
newValue = newValue instanceof JSONObject ? ((JSONObject) newValue).toMap() : newValue;
}
return new AuditLogChange(oldValue, newValue, key);
}
代码示例来源:origin: DV8FromTheWorld/JDA
private void createGuildEmotePass(GuildImpl guildObj, JSONArray array)
{
if (!getJDA().isCacheFlagSet(CacheFlag.EMOTE))
return;
TLongObjectMap<Emote> emoteMap = guildObj.getEmoteMap();
for (int i = 0; i < array.length(); i++)
{
JSONObject object = array.getJSONObject(i);
if (object.isNull("id"))
{
LOG.error("Received GUILD_CREATE with an emoji with a null ID. JSON: {}", object);
continue;
}
final long emoteId = object.getLong("id");
emoteMap.put(emoteId, createEmote(guildObj, object, false));
}
}
代码示例来源:origin: DV8FromTheWorld/JDA
public void onCreate(long id, JSONObject obj)
{
boolean available = obj.isNull("unavailable") || !obj.getBoolean("unavailable");
log.trace("Received guild create for id: {} available: {}", id, available);
GuildSetupNode node = setupNodes.get(id);
if (node == null)
{
// this is a join event
node = new GuildSetupNode(id, this, true);
setupNodes.put(id, node);
// do not increment incomplete counter, it is only relevant to init guilds
}
else if (node.markedUnavailable && available && incompleteCount > 0)
{
//Looks like this guild decided to become available again during startup
// that means we can now consider it for ReadyEvent status again!
if (node.sync)
syncingCount++;
incompleteCount++;
}
node.handleCreate(obj);
}
代码示例来源:origin: DV8FromTheWorld/JDA
@Override
protected Long handleInternally(JSONObject content)
{
final Long guildId = content.isNull("guild_id") ? null : content.getLong("guild_id");
if (guildId != null && getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
if (guildId != null)
handleGuildVoiceState(content);
else
handleCallVoiceState(content);
return null;
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/* package for test */ Object convertCloudResponse(Object result) {
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
// We want to make sure we pass back a null result as null, and not a JSONObject
if (jsonResult.isNull("result")) {
return null;
}
result = jsonResult.opt("result");
}
ParseDecoder decoder = ParseDecoder.get();
Object finalResult = decoder.decode(result);
if (finalResult != null) {
return finalResult;
}
return result;
}
}
内容来源于网络,如有侵权,请联系作者删除!