本文整理了Java中org.json.simple.JSONObject.containsKey()
方法的一些代码示例,展示了JSONObject.containsKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.containsKey()
方法的具体详情如下:
包路径:org.json.simple.JSONObject
类名称:JSONObject
方法名:containsKey
暂无
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Attempt to convert the message to its plaintext representation.
*
* @return The plain text, or the empty string on failure.
*/
public String asPlaintext() {
if (object.containsKey("text")) {
Object obj = object.get("text");
if (obj instanceof String) {
return (String) obj;
}
}
return "";
}
代码示例来源:origin: apache/storm
Object obj = parser.parse(input);
JSONObject jsonObject = (JSONObject) obj;
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) {
Double topoMemOnHeap = ObjectReader
.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, topoMemOnHeap);
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) {
Double topoMemOffHeap = ObjectReader
.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, topoMemOffHeap);
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT)) {
Double topoCpu = ObjectReader.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT),
null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, topoCpu);
代码示例来源:origin: apache/storm
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) {
Double topoMemOnHeap = ObjectReader
.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, topoMemOnHeap);
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) {
Double topoMemOffHeap = ObjectReader
.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, topoMemOffHeap);
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT)) {
Double topoCpu = ObjectReader.getDouble(jsonObject.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT),
null);
topologyResources.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, topoCpu);
if (jsonObject.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP)) {
Map<String, Number> rawResourcesMap =
(Map<String, Number>) jsonObject.computeIfAbsent(
代码示例来源:origin: GlowstoneMC/Glowstone
private static void flatten(StringBuilder dest, JSONObject obj) {
if (obj.containsKey("color")) {
try {
dest.append(ChatColor.valueOf(obj.get("color").toString().toUpperCase()));
} catch (IllegalArgumentException ex) {
// invalid color, ignore
}
}
for (ChatColor format : FORMATTING) {
String name = format == ChatColor.MAGIC ? "obfuscated" : format.name().toLowerCase();
if (obj.containsKey(name) && obj.get(name).equals(true)) {
dest.append(format);
}
}
if (obj.containsKey("text")) {
dest.append(obj.get("text"));
}
if (obj.containsKey("extra")) {
LinkedList<?> array = (LinkedList<?>) obj.get("extra");
for (Object o : array) {
if (o instanceof JSONObject) {
flatten(dest, (JSONObject) o);
} else {
dest.append(o);
}
}
}
}
代码示例来源:origin: SonarSource/sonarqube
private boolean compareObjects(JSONObject expectedMap, JSONObject actualMap) {
// each key-value of expected map must exist in actual map
for (Map.Entry<Object, Object> expectedEntry : (Set<Map.Entry<Object, Object>>) expectedMap.entrySet()) {
Object key = expectedEntry.getKey();
if (shouldIgnoreField(key)) {
continue;
}
if (!actualMap.containsKey(key)) {
return false;
}
if (!compare(expectedEntry.getValue(), actualMap.get(key))) {
return false;
}
}
return true;
}
代码示例来源:origin: GlowstoneMC/Glowstone
if (!object.containsKey("count")) {
this.min = Optional.empty();
this.max = Optional.empty();
return;
Object count = object.get("count");
if (count instanceof Long) {
this.min = Optional.of(((Long) count).intValue());
if (object.containsKey("min")) {
this.min = Optional.of(((Long) object.get("min")).intValue());
} else {
this.min = Optional.of(0);
this.max = Optional.of(((Long) object.get("max")).intValue());
代码示例来源:origin: GlowstoneMC/Glowstone
if (object.containsKey("item")) { // NON-NLS
type = Optional.of(new ProbableValue<>(object, "item"));
} else {
type = Optional.empty();
if (object.containsKey("data")) { // NON-NLS
Object data = object.get("data"); // NON-NLS
if (data instanceof String) {
this.reflectiveData = Optional.of(new ReflectiveValue<Integer>((String) data));
reflectiveData = Optional.empty();
if (object.containsKey("count")) { // NON-NLS
count = Optional.of(new LootRandomValues(object));
} else {
count = Optional.empty();
condition = (String) object.get("condition"); // NON-NLS
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Parses a loot-table entry from JSON.
*
* @param object a loot-table entry in JSON format.
*/
public DefaultLootItem(JSONObject object) {
this.type = new ProbableValue<>(object, "item");
this.count = new LootRandomValues(object);
if (object.containsKey("data")) { // NON-NLS
final Object data = object.get("data"); // NON-NLS
if (data instanceof String) {
this.reflectiveData = Optional
.of(new ReflectiveValue<Integer>((String) data));
this.data = Optional.empty();
} else if (data instanceof Long) {
this.reflectiveData = Optional
.of(new ReflectiveValue<>(((Long) data).intValue()));
this.data = Optional.empty();
} else {
this.reflectiveData = Optional.empty();
this.data = Optional.of(new ProbableValue<>(object, "data"));
}
} else {
this.reflectiveData = Optional.of(new ReflectiveValue<>(0));
this.data = Optional.empty();
}
}
}
代码示例来源:origin: LawnchairLauncher/Lawnchair
if (!json.containsKey("travis_build_number")) {
return null;
int buildNumber = Integer.valueOf((String) json.get("travis_build_number"));
String version = (String) json.get("app_version");
String downloadUrl = String.format(Updater.DOWNLOAD_URL, version);
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Parses a loot table from JSON.
*
* @param object a loot table in JSON form
*/
public EntityLootTable(JSONObject object) {
if (object.containsKey("experience")) { // NON-NLS
this.experience
= new LootRandomValues((JSONObject) object.get("experience")); // NON-NLS
} else {
this.experience = null;
}
if (object.containsKey("items")) { // NON-NLS
JSONArray array = (JSONArray) object.get("items"); // NON-NLS
this.items = new LootItem[array.size()];
for (int i = 0; i < array.size(); i++) {
JSONObject json = (JSONObject) array.get(i);
this.items[i] = new LootItem(json);
}
} else {
this.items = NO_ITEMS;
}
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
} else if (entry.getValue() instanceof JSONObject) {
JSONObject object = (JSONObject) entry.getValue();
if (object.containsKey("value")) { // NON-NLS
longValue = (Long) object.get("value"); // NON-NLS
代码示例来源:origin: GlowstoneMC/Glowstone
securityKey = (String) payload.get("s"); // Not used by us anywhere
name = (String) payload.get("n");
hostname = (String) payload.get("h");
uuid = UuidUtils.fromFlatString((String) payload.get("u"));
address = new InetSocketAddress(
if (payload.containsKey("p")) {
JSONArray props = (JSONArray) payload.get("p");
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Reads a LootItem from its JSON form.
*
* @param object a LootItem in JSON form
*/
public LootItem(JSONObject object) {
defaultItem = new DefaultLootItem((JSONObject) object.get("default"));
if (object.containsKey("conditions")) {
JSONArray array = (JSONArray) object.get("conditions");
conditionalItems = new ConditionalLootItem[array.size()];
for (int i = 0; i < array.size(); i++) {
JSONObject json = (JSONObject) array.get(i);
conditionalItems[i] = new ConditionalLootItem(json);
}
} else {
conditionalItems = NO_ITEMS;
}
}
}
代码示例来源:origin: ethereum/ethereumj
JSONObject envJSON = (JSONObject) testCaseJSONObj.get("env");
JSONObject execJSON = (JSONObject) testCaseJSONObj.get("exec");
JSONObject preJSON = (JSONObject) testCaseJSONObj.get("pre");
JSONObject postJSON = new JSONObject();
if (testCaseJSONObj.containsKey("post")) {
if (testCaseJSONObj.containsKey("callcreates"))
callCreates = (JSONArray) testCaseJSONObj.get("callcreates");
if (testCaseJSONObj.containsKey("logs"))
logsJSON = testCaseJSONObj.get("logs");
logs = new Logs(logsJSON);
if (testCaseJSONObj.containsKey("gas"))
gasString = testCaseJSONObj.get("gas").toString();
this.gas = BigIntegers.asUnsignedByteArray(toBigInt(gasString));
if (testCaseJSONObj.containsKey("out"))
outString = testCaseJSONObj.get("out").toString();
if (outString != null && outString.length() > 2)
if (testCaseJSONObj.containsKey("env"))
this.env = new Env(envJSON);
if (testCaseJSONObj.containsKey("exec"))
this.exec = new Exec(execJSON);
代码示例来源:origin: scouter-project/scouter
try {
JSONObject json = (JSONObject) parser.parse(in);
JSONObject objectInfo = (JSONObject) json.get("object");
JSONArray countersArray = (JSONArray) json.get("counters");
String objType = (String) objectInfo.get("type");
objectType = new ObjectType();
objectType.setName(objType);
if (objectInfo.containsKey("display")) {
if (counterInfo.containsKey("display")) {
if (counterInfo.containsKey("total")) {
if (counterInfo.containsKey("all")) {
addObjectType.setIcon(objectType.getIcon());
addObjectType.setSubObject(objectType.isSubObject());
if (objectInfo.containsKey("display")) {
if (counterInfo.containsKey("display")) {
if (counterInfo.containsKey("total")) {
if (counterInfo.containsKey("all")) {
代码示例来源:origin: apache/metron
@SuppressWarnings("unchecked")
private JSONObject convertToInt(JSONObject obj, String key) {
if (obj.containsKey(key)) {
obj.put(key, Integer.valueOf((String) obj.get(key)));
}
return obj;
}
代码示例来源:origin: apache/metron
public String getKey(JSONObject value) {
try {
String ipSrcAddr = null;
String ipDstAddr = null;
if (value.containsKey("ip_src_addr"))
ipSrcAddr = value.get("ip_src_addr").toString();
if (value.containsKey("ip_dst_addr"))
ipDstAddr = value.get("ip_dst_addr").toString();
if (ipSrcAddr == null && ipDstAddr == null)
return "0";
if (ipSrcAddr == null || ipSrcAddr.length() == 0)
return ipDstAddr;
if (ipDstAddr == null || ipDstAddr.length() == 0)
return ipSrcAddr;
double ip1 = Double.parseDouble(ipSrcAddr.replace(".", ""));
double ip2 = Double.parseDouble(ipDstAddr.replace(".", ""));
return String.valueOf(ip1 + ip2);
} catch (Exception e) {
return "0";
}
}
}
代码示例来源:origin: apache/metron
@Override
public Optional<Long> currentTimeMillis(JSONObject message) {
Long result;
if(message != null && message.containsKey(timestampField)) {
// extract the timestamp and convert to a long
Object timestamp = message.get(timestampField);
result = ConversionUtils.convert(timestamp, Long.class);
} else {
// the message does not contain the specified timestamp field
LOG.debug("message does not contain timestamp field '{}': message will be ignored: message='{}'",
timestampField, JSONObject.toJSONString(message));
result = null;
}
return Optional.ofNullable(result);
}
}
代码示例来源:origin: rhuss/jolokia
private void verifyBulkJsonResponse(JSONAware pJsonResponse) throws J4pException {
if (!(pJsonResponse instanceof JSONArray)) {
if (pJsonResponse instanceof JSONObject) {
JSONObject errorObject = (JSONObject) pJsonResponse;
if (!errorObject.containsKey("status") || (Long) errorObject.get("status") != 200) {
throw new J4pRemoteException(null, errorObject);
}
}
throw new J4pException("Invalid JSON answer for a bulk request (expected an array but got a " + pJsonResponse.getClass() + ")");
}
}
代码示例来源:origin: rhuss/jolokia
public <RESP extends J4pResponse<REQ>, REQ extends J4pRequest> RESP extract(REQ pRequest,
JSONObject pJsonResp)
throws J4pRemoteException {
int status = 0;
if( pJsonResp.containsKey("status")) {
Object o = pJsonResp.get("status");
if( o instanceof Long ) {
status = ((Long)o).intValue();
}
}
if (!allowedCodes.contains(status)) {
throw new J4pRemoteException(pRequest, pJsonResp);
}
return status == 200 ? pRequest.<RESP>createResponse(pJsonResp) : null;
}
}
内容来源于网络,如有侵权,请联系作者删除!