本文整理了Java中com.google.gwt.json.client.JSONObject.containsKey()
方法的一些代码示例,展示了JSONObject.containsKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.containsKey()
方法的具体详情如下:
包路径:com.google.gwt.json.client.JSONObject
类名称:JSONObject
方法名:containsKey
[英]Tests whether or not this JSONObject contains the specified property.
[中]测试此JSONObject是否包含指定的属性。
代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-gwt-extra
public Object deserialize(JSONValue jsonValue) {
JSONObject obj = jsonValue.isObject();
if (obj != null) {
if (obj.containsKey("class") && obj.get("class").isString() != null) {
return serializer.deSerialize(jsonValue, obj.get("class").isString().stringValue());
}
}
throw new IllegalArgumentException("Json string must contain \"class\" key.");
}
代码示例来源:origin: org.geomajas/geomajas-client-gwt2-impl
private Feature createFeature(JSONObject jsonObject, FeaturesSupported layer) {
String id = null;
if (jsonObject.containsKey("id")) {
id = JsonService.getStringValue(jsonObject, "id");
} else {
JSONValue value = properties.get(name);
Attribute attribute;
if (value.isBoolean() != null) {
} else if (value.isNumber() != null) {
attribute = new AttributeImpl(JsonService.getDoubleValue(properties, name));
} else if (value.isObject() != null) {
attribute = new AttributeImpl(JsonService.getGeometryValue(properties, name));
} else {
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-maven-shared
public static ArchetypeOutputImpl fromJsonObjectInt(JSONValue jsonValue, boolean copyJsons) {
if (jsonValue == null || jsonValue.isNull() != null) {
return null;
}
ArchetypeOutputImpl dto = new ArchetypeOutputImpl();
JSONObject json = jsonValue.isObject();
if (json.containsKey("state")) {
JSONValue stateIn = json.get("state");
org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State stateOut = org.eclipse.che.plugin.maven.shared.dto.ArchetypeOutput.State.valueOf(stateIn.isString().stringValue());
dto.setState(stateOut);
}
if (json.containsKey("output")) {
JSONValue outputIn = json.get("output");
String outputOut = outputIn.isString() != null ? outputIn.isString().stringValue() : null;
dto.setOutput(outputOut);
}
return dto;
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-yaml-shared
public static YamlDTOImpl fromJsonObjectInt(JSONValue jsonValue, boolean copyJsons) {
if (jsonValue == null || jsonValue.isNull() != null) {
return null;
}
YamlDTOImpl dto = new YamlDTOImpl();
JSONObject json = jsonValue.isObject();
if (json.containsKey("schemas")) {
JSONValue schemasIn = json.get("schemas");
java.util.Map<java.lang.String, java.lang.String> schemasOut = null;
if (schemasIn != null && schemasIn.isNull() == null) {
schemasOut = new java.util.HashMap<java.lang.String, java.lang.String>();
java.util.Set<String> keySet0 = schemasIn.isObject().keySet();
for (String key0 : keySet0) {
JSONValue schemasIn_ = schemasIn.isObject().get(key0);
String schemasOut_ = schemasIn_.isString() != null ? schemasIn_.isString().stringValue() : null;
schemasOut.put(key0, schemasOut_);
}
}
dto.setSchemas(schemasOut);
}
return dto;
}
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-maven-shared
if (json.containsKey("version")) {
JSONValue versionIn = json.get("version");
String versionOut = versionIn.isString() != null ? versionIn.isString().stringValue() : null;
dto.setVersion(versionOut);
if (json.containsKey("repository")) {
JSONValue repositoryIn = json.get("repository");
String repositoryOut = repositoryIn.isString() != null ? repositoryIn.isString().stringValue() : null;
dto.setRepository(repositoryOut);
if (json.containsKey("properties")) {
JSONValue propertiesIn = json.get("properties");
java.util.Map<java.lang.String, java.lang.String> propertiesOut = null;
if (propertiesIn != null && propertiesIn.isNull() == null) {
propertiesOut = new java.util.HashMap<java.lang.String, java.lang.String>();
java.util.Set<String> keySet0 = propertiesIn.isObject().keySet();
for (String key0 : keySet0) {
JSONValue propertiesIn_ = propertiesIn.isObject().get(key0);
String propertiesOut_ = propertiesIn_.isString() != null ? propertiesIn_.isString().stringValue() : null;
propertiesOut.put(key0, propertiesOut_);
if (json.containsKey("artifactId")) {
JSONValue artifactIdIn = json.get("artifactId");
String artifactIdOut = artifactIdIn.isString() != null ? artifactIdIn.isString().stringValue() : null;
if (json.containsKey("groupId")) {
JSONValue groupIdIn = json.get("groupId");
String groupIdOut = groupIdIn.isString() != null ? groupIdIn.isString().stringValue() : null;
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-debugger-ide
if (json.containsKey("name")) {
JSONValue nameIn = json.get("name");
String nameOut = nameIn.isString() != null ? nameIn.isString().stringValue() : null;
dto.setName(nameOut);
if (json.containsKey("port")) {
JSONValue portIn = json.get("port");
int portOut = (int)portIn.isNumber().doubleValue();
dto.setPort(portOut);
if (json.containsKey("type")) {
JSONValue typeIn = json.get("type");
String typeOut = typeIn.isString() != null ? typeIn.isString().stringValue() : null;
dto.setType(typeOut);
if (json.containsKey("connectionProperties")) {
JSONValue connectionPropertiesIn = json.get("connectionProperties");
java.util.Map<java.lang.String, java.lang.String> connectionPropertiesOut = null;
if (connectionPropertiesIn != null && connectionPropertiesIn.isNull() == null) {
connectionPropertiesOut = new java.util.HashMap<java.lang.String, java.lang.String>();
java.util.Set<String> keySet0 = connectionPropertiesIn.isObject().keySet();
for (String key0 : keySet0) {
JSONValue connectionPropertiesIn_ = connectionPropertiesIn.isObject().get(key0);
String connectionPropertiesOut_ = connectionPropertiesIn_.isString() != null ? connectionPropertiesIn_.isString().stringValue() : null;
connectionPropertiesOut.put(key0, connectionPropertiesOut_);
if (json.containsKey("host")) {
JSONValue hostIn = json.get("host");
String hostOut = hostIn.isString() != null ? hostIn.isString().stringValue() : null;
代码示例来源:origin: tadglines/Socket.IO-Java
private void onMessage(JSONObject obj) {
if (obj.containsKey("welcome")) {
JSONString str = obj.get("welcome").isString();
if (str != null) {
addLine("<em><b>" + str.stringValue() + "</b></em>");
}
} else if (obj.containsKey("announcement")) {
JSONString str = obj.get("announcement").isString();
if (str != null) {
addLine("<em>" + str.stringValue() + "</em>");
}
} else if (obj.containsKey("message")) {
JSONArray arr = obj.get("message").isArray();
if (arr != null && arr.size() >= 2) {
JSONString id = arr.get(0).isString();
JSONString msg = arr.get(1).isString();
if (id != null && msg != null) {
addLine("<b>" + id.stringValue() + ":</b> " + msg.stringValue());
}
}
}
}
代码示例来源:origin: org.codehaus.sonar/sonar-gwt-api
public static void dispatchJSON(JavaScriptObject jsonObj, JSONHandler handler) {
JSONObject obj = new JSONObject(jsonObj);
if (obj.isObject() != null) {
if (obj.containsKey("err_code")) {
handler.onError(new Double(obj.get("err_code").isNumber().doubleValue()).intValue(),
obj.get("err_msg").isString().stringValue());
return;
}
}
handler.onResponse(jsonObj);
}
代码示例来源:origin: org.n52.sensorweb/sensorwebclient-ui
private static TimeseriesRenderingOptions createRenderingOptions(String options) {
if (options == null) {
return new TimeseriesRenderingOptions();
}
TimeseriesRenderingOptions tsOptions = new TimeseriesRenderingOptions();
JSONObject tsRenderingOptions = new JSONObject(parseUntrustedJson(options));
if (tsRenderingOptions.containsKey("color")) {
JSONString color = tsRenderingOptions.get("color").isString();
tsOptions.setColor(color.stringValue());
}
if (tsRenderingOptions.containsKey("lineWidth")) {
JSONNumber lineWidth = tsRenderingOptions.get("lineWidth").isNumber();
tsOptions.setLineWidth((int)lineWidth.doubleValue());
}
return tsOptions;
}
代码示例来源:origin: org.jboss.as/jboss-as-console-dmr
@Override
public ModelNode get() {
ModelNode node;
if (contentType.startsWith(APPLICATION_DMR_ENCODED)) {
node = ModelNode.fromBase64(payload);
} else if (contentType.startsWith(APPLICATION_JSON)) {
node = new ModelNode();
JSONObject response = JSONParser.parseLenient(payload).isObject();
JSONString outcome = response.get(OUTCOME).isString();
node.get(OUTCOME).set(outcome.stringValue());
if (outcome.stringValue().equals(SUCCESS)) {
if (response.containsKey(RESULT) && response.get(RESULT).isObject() != null) {
node.get(RESULT).set(stringify(response.get(RESULT).isObject().getJavaScriptObject(), 2));
} else {
node.get(RESULT).set(new ModelNode());
}
} else {
String failure = extractFailure(response);
node.get(FAILURE_DESCRIPTION).set(failure);
}
} else {
node = new ModelNode();
node.get(OUTCOME).set(FAILED);
node.get(FAILURE_DESCRIPTION).set("Unable to parse response with content-type " + contentType);
}
return node;
}
代码示例来源:origin: hpehl/piriti
assertTrue(jsonObject.containsKey("booleanPrimitive"));
assertNotNull(jsonObject.get("booleanPrimitive").isBoolean());
assertFalse(jsonObject.get("booleanPrimitive").isBoolean().booleanValue());
assertTrue(jsonObject.containsKey("booleanObject"));
assertSame(JSONNull.getInstance(), jsonObject.get("booleanObject").isNull());
assertTrue(jsonObject.containsKey("bytePrimitive"));
assertSame(JSONNull.getInstance(), jsonObject.get("byteObject").isNull());
assertTrue(jsonObject.containsKey("characterPrimitive"));
assertNotNull(jsonObject.get("characterPrimitive").isString());
assertEquals(String.valueOf('\0'), jsonObject.get("characterPrimitive").isString().stringValue());
assertSame(JSONNull.getInstance(), jsonObject.get("characterObject").isNull());
assertTrue(jsonObject.containsKey("doublePrimitive"));
assertTrue(jsonObject.containsKey("floatPrimitive"));
assertTrue(jsonObject.containsKey("integerPrimitive"));
assertTrue(jsonObject.containsKey("longPrimitive"));
assertTrue(jsonObject.containsKey("shortPrimitive"));
assertTrue(jsonObject.containsKey("date"));
assertNotNull(jsonObject.get("date").isNull());
assertTrue(jsonObject.containsKey("sqlDate"));
assertNotNull(jsonObject.get("sqlDate").isNull());
assertTrue(jsonObject.containsKey("time"));
assertNotNull(jsonObject.get("time").isNull());
assertTrue(jsonObject.containsKey("timestamp"));
内容来源于网络,如有侵权,请联系作者删除!