本文整理了Java中elemental.json.JsonObject
类的一些代码示例,展示了JsonObject
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject
类的具体详情如下:
包路径:elemental.json.JsonObject
类名称:JsonObject
[英]Represents a Json object.
[中]表示Json对象。
代码示例来源:origin: com.vaadin/vaadin-server
public String asJson() {
JsonArray uris = Json.createArray();
for (String uri : sourceUris) {
uris.set(uris.length(), uri);
}
JsonObject object = Json.createObject();
object.put("version", Version.getFullVersion());
object.put("timestamp", Long.toString(timestamp));
object.put("uris", uris);
object.put("css", css);
return object.toJson();
}
代码示例来源:origin: com.vaadin/vaadin-server
JsonValue token = json.get(ApplicationConstants.CSRF_TOKEN);
if (token == null) {
csrfToken = ApplicationConstants.CSRF_TOKEN_DEFAULT_VALUE;
.isSyncIdCheckEnabled()) {
syncId = (int) json
.getNumber(ApplicationConstants.SERVER_SYNC_ID);
} else {
syncId = -1;
if (json.hasKey(ApplicationConstants.RESYNCHRONIZE_ID)) {
resynchronize = json
.getBoolean(ApplicationConstants.RESYNCHRONIZE_ID);
} else {
resynchronize = false;
if (json.hasKey(ApplicationConstants.WIDGETSET_VERSION_ID)) {
widgetsetVersion = json
.getString(ApplicationConstants.WIDGETSET_VERSION_ID);
if (json.hasKey(ApplicationConstants.CLIENT_TO_SERVER_ID)) {
clientToServerMessageId = (int) json
.getNumber(ApplicationConstants.CLIENT_TO_SERVER_ID);
} else {
getLogger()
invocations = json.getArray(ApplicationConstants.RPC_INVOCATIONS);
代码示例来源:origin: com.vaadin/vaadin-server
private static boolean jsonObjectEquals(JsonObject a, JsonObject b) {
String[] keys = a.keys();
if (keys.length != b.keys().length) {
return false;
}
for (String key : keys) {
JsonValue value = b.get(key);
if (value == null || !jsonEquals(a.get(key), value)) {
return false;
}
}
return true;
}
代码示例来源:origin: com.vaadin/vaadin-server
public ScssCacheEntry(JsonObject json) {
css = json.getString("css");
timestamp = Long.parseLong(json.getString("timestamp"));
sourceUris = new ArrayList<>();
JsonArray uris = json.getArray("uris");
for (int i = 0; i < uris.length(); i++) {
sourceUris.add(uris.getString(i));
}
// Not set for cache entries read from disk
scssFileName = null;
}
代码示例来源:origin: com.vaadin/vaadin-server
private String getConfigOrNull(String name) {
JsonObject parameters = context.getApplicationParameters();
if (parameters.hasKey(name)) {
return parameters.getString(name);
} else {
return null;
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
boolean skipRestoreDimensions) {
if (partStackState.hasKey(PART_STACK_PARTS)) {
JsonArray parts = partStackState.get(PART_STACK_PARTS);
for (int i = 0; i < parts.length(); i++) {
JsonObject value = parts.get(i);
if (value.hasKey(PART_CLASS_NAME)) {
String className = value.getString(PART_CLASS_NAME);
Provider<PartPresenter> provider = dynaProvider.getProvider(className);
if (provider != null) {
if (partStackState.hasKey(ACTIVE_PART)) {
String activePart = partStackState.getString(ACTIVE_PART);
Provider<PartPresenter> provider = dynaProvider.getProvider(activePart);
if (provider != null) {
if (partStackState.hasKey(HIDDEN_STATE) && partStackState.getBoolean(HIDDEN_STATE)) {
if (partStackState.hasKey(PART_STACK_SIZE)) {
double size = partStackState.getNumber(PART_STACK_SIZE);
代码示例来源:origin: org.eclipse.che.plugin/che-plugin-yaml-ide
/**
* Converts json string to list of Yaml Preferences
*
* @param jsonStr The json string to turn into the list of Yaml Preferences
* @return List of Yaml Preferences
*/
private List<YamlPreference> jsonToYamlPreference(String jsonStr) {
ArrayList yamlPreferences = new ArrayList<YamlPreference>();
JsonObject parsedJson = Json.parse(jsonStr);
for (String glob : parsedJson.keys()) {
try {
JsonArray jsonArray = parsedJson.getArray(glob);
for (int arrNum = 0; arrNum < jsonArray.length(); arrNum++) {
YamlPreference newYamlPref = new YamlPreference(jsonArray.getString(arrNum), glob);
yamlPreferences.add(newYamlPref);
}
} catch (Exception e) {
LOG.debug(e.getMessage(), e);
}
}
return yamlPreferences;
}
代码示例来源:origin: com.haulmont.cuba/cuba-web-toolkit
protected void addItems(JsonArray items, HasWidgets container) {
for (int i = 0; i < items.length(); i++) {
JsonObject itemJson = items.getObject(i);
String iconId = itemJson.getString("icon");
if (menuItemIconSupplier != null && iconId != null) {
icon = menuItemIconSupplier.apply(iconId);
if (itemJson.hasKey("captionAsHtml")) {
captionAsHtml = itemJson.getBoolean("captionAsHtml");
itemJson.getString("id"),
icon,
itemJson.getString("styleName"),
itemJson.getString("caption"),
captionAsHtml);
menuItemWidget.setDescription(itemJson.getString("description"));
menuItemWidget.setCubaId(itemJson.getString("cubaId"));
menuItemWidget.setBadgeText(itemJson.getString("badgeText"));
JsonArray childrenItemsJson = itemJson.getArray("children");
if (childrenItemsJson != null) {
MenuContainerWidget menuContainerWidget = new MenuContainerWidget(this, menuItemWidget);
if (itemJson.hasKey("expanded")
&& itemJson.getBoolean("expanded")) {
menuContainerWidget.setExpanded(true);
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
private List<Promise<Void>> restore(
JsonObject files,
EditorPartStack editorPartStack,
Map<EditorPartPresenter, EditorPartStack> activeEditors) {
if (files.hasKey("FILES")) {
// plain
JsonArray filesArray = files.getArray("FILES");
List<Promise<Void>> promises = new ArrayList<>();
for (int i = 0; i < filesArray.length(); i++) {
JsonObject file = filesArray.getObject(i);
Promise<Void> openFile = openFile(file, editorPartStack, activeEditors);
promises.add(openFile);
}
return promises;
} else {
// split
return restoreSplit(files, editorPartStack, activeEditors);
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
@Override
public Promise<Void> loadState(@NotNull JsonObject state) {
if (state.hasKey(SHOW_HIDDEN_FILES)) {
projectExplorer.showHiddenFiles(state.getBoolean(SHOW_HIDDEN_FILES));
state.hasKey(PATH_PARAM_ID) ? state.getArray(PATH_PARAM_ID) : Json.createArray();
if (paths.length() == 0) {
return promises.resolve(null);
loader.show();
for (int i = 0; i < paths.length(); i++) {
String path = paths.getString(i);
if (revealPromise == null) {
revealPromise = revealer.reveal(Path.valueOf(path), false).thenPromise(this::doExpand);
代码示例来源:origin: com.haulmont.cuba/cuba-web-toolkit
protected void showSuggestions(JsonArray suggestions) {
this.suggestions.clear();
for (int i = 0; i < suggestions.length(); i++) {
JsonObject jsonSuggestion = suggestions.getObject(i);
Suggestion suggestion = new Suggestion(
jsonSuggestion.getString(SUGGESTION_ID),
jsonSuggestion.getString(SUGGESTION_CAPTION),
jsonSuggestion.getString(SUGGESTION_STYLE_NAME)
);
this.suggestions.add(suggestion);
}
showSuggestions();
}
代码示例来源:origin: com.vaadin/hummingbird-server
private static void includeDependencies(Element head,
JsonObject initialUIDL, BootstrapContext context) {
// Extract style sheets and load them eagerly
JsonArray dependencies = initialUIDL
.getArray(DependencyList.DEPENDENCY_KEY);
if (dependencies == null || dependencies.length() == 0) {
// No dependencies at all
return;
}
Predicate<? super JsonObject> includeStyleSheets = object -> DependencyList.TYPE_STYLESHEET
.equals(object.getString(DependencyList.KEY_TYPE));
com.vaadin.hummingbird.util.JsonUtil.objectStream(dependencies)
.filter(includeStyleSheets).forEach(stylesheet -> {
Element link = head.appendElement("link");
link.attr("rel", "stylesheet");
link.attr("type", "text/css");
String url = stylesheet.getString(DependencyList.KEY_URL);
url = context.getUriResolver().resolveVaadinUri(url);
link.attr("href", url);
});
// Remove from initial UIDL
JsonArray otherDependencies = com.vaadin.hummingbird.util.JsonUtil
.objectStream(dependencies).filter(includeStyleSheets.negate())
.collect(com.vaadin.hummingbird.util.JsonUtil.asArray());
initialUIDL.put(DependencyList.DEPENDENCY_KEY, otherDependencies);
}
代码示例来源:origin: com.googlecode.gwtquery/gwtquery
private String param(JsonObject o) {
String ret = "";
for (String k : o.keys()) {
ret += ret.isEmpty() ? "" : "&";
JsonValue v = o.get(k);
if (v instanceof JsonArray) {
for (int i = 0, l = ((JsonArray) v).length(); i < l; i++) {
ret += i > 0 ? "&" : "";
JsonValue e = ((JsonArray) v).get(i);
ret += k + "[]=" + e.toJson();
}
} else {
if (v != null && !(v instanceof JsonNull)) {
ret += k + "=" + v.toJson();
}
}
}
return ret;
}
代码示例来源:origin: com.vaadin/vaadin-server
if (LegacyCommunicationManager
.isConnectorVisibleToClient(child)) {
children.set(children.length(), child.getConnectorId());
if (children.length() > 0
|| !stateUpdateConnectors.contains(connectorId)) {
try {
hierarchyInfo.put(connectorId, children);
} catch (JsonException e) {
throw new PaintException(
代码示例来源:origin: com.googlecode.gwtquery/gwtquery
if (clz.equals(Boolean.class) || clz == Boolean.TYPE) {
try {
return obj != null ? obj.getBoolean(attr) : arr.getBoolean(idx);
} catch (Exception e) {
return Boolean.FALSE;
return new Date((long) (obj != null ? obj.getNumber(attr) : arr.getNumber(idx)));
} else if (clz.equals(Byte.class) || clz == Byte.TYPE) {
return toDouble(attr, arr, idx, obj).byteValue();
Object ret = obj != null ? obj.get(attr) : arr.get(idx);
if (ret instanceof JreJsonFunction || clz.equals(Function.class)) {
return ret != null && ret instanceof JreJsonFunction ? ((JreJsonFunction) ret).getFunction()
return jsonArrayToList(obj.getArray(attr), ctype, clz.isArray());
} else if (ret instanceof JsonObject) {
if (clz == Object.class) {
代码示例来源:origin: com.vaadin/vaadin-server
private JsonArray toJsonArray(List<Dependency> list) {
JsonArray result = Json.createArray();
for (int i = 0; i < list.size(); i++) {
JsonObject dep = Json.createObject();
Dependency dependency = list.get(i);
dep.put("type", dependency.getType().name());
dep.put("url", dependency.getUrl());
result.set(i, dep);
}
return result;
}
代码示例来源:origin: com.vaadin/vaadin-server
private void putValueOrNull(JsonObject object, String key, String value) {
assert object != null;
assert key != null;
if (value == null) {
object.put(key, Json.createNull());
} else {
object.put(key, value);
}
}
}
代码示例来源:origin: com.vaadin/vaadin-upload-flow
private String getStringObject(String propertyName, String subName) {
String result = null;
JsonObject json = (JsonObject) getElement()
.getPropertyRaw(propertyName);
if (json != null && json.hasKey(subName)
&& !(json.get(subName) instanceof JsonNull)) {
result = json.getString(subName);
}
return result;
}
代码示例来源:origin: com.vaadin/flow-maven-plugin
JsonArray fragmentFiles;
try {
fragmentFiles = fragment.getArray("files");
if (fragmentFiles == null) {
throw new IllegalStateException(String.format(
.newHashSetWithExpectedSize(fragmentFiles.length());
for (int j = 0; j < fragmentFiles.length(); ++j) {
try {
files.add(fragmentFiles.getString(j));
} catch (JsonException | ClassCastException e) {
throw new IllegalStateException(String.format(
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
/**
* Determines whether perspective is maximized.
*
* @param partStacksState part stack state
* @return <b>true</b> is perspective has maximized part stack
*/
private boolean isPerspectiveMaximized(JsonObject partStacksState) {
for (String partStackType : partStacksState.keys()) {
JsonObject partStackState = partStacksState.getObject(partStackType);
if (partStackState.hasKey(PART_STACK_STATE)
&& PartStack.State.MAXIMIZED.name().equals(partStackState.getString(PART_STACK_STATE))) {
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!