本文整理了Java中com.eclipsesource.json.Json.array()
方法的一些代码示例,展示了Json.array()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.array()
方法的具体详情如下:
包路径:com.eclipsesource.json.Json
类名称:Json
方法名:array
[英]Creates a new empty JsonArray. This is equivalent to creating a new JsonArray using the constructor.
[中]创建一个新的空JsonArray。这相当于使用构造函数创建一个新的JsonArray。
代码示例来源:origin: com.tcdng.unify/unify-core
@SuppressWarnings("unchecked")
@Override
public JsonValue write(Object value) throws Exception {
JsonArray array = (JsonArray) Json.array();
T[] arrayValues = (T[]) value;
for (int i = 0; i < arrayValues.length; i++) {
array.add(setValue(arrayValues[i]));
}
return array;
}
代码示例来源:origin: mokies/ratelimitj
String encode(Iterable<RequestLimitRule> rules) {
JsonArray jsonArray = Json.array().asArray();
rules.forEach(rule -> jsonArray.add(toJsonArray(rule)));
return jsonArray.toString();
}
代码示例来源:origin: fabienrenaud/java-json-benchmark
@Override
public com.eclipsesource.json.JsonValue minimaljson(Users obj) throws IOException {
com.eclipsesource.json.JsonObject jso = com.eclipsesource.json.Json.object();
if (obj.users != null) {
com.eclipsesource.json.JsonArray jsarr = (com.eclipsesource.json.JsonArray) com.eclipsesource.json.Json.array();
for (User u : obj.users) {
jsarr.add(minimaljson(u));
}
jso.add("users", jsarr);
}
return jso;
}
代码示例来源:origin: com.tcdng.unify/unify-core
if (converter == null) {
if (Collection.class.isAssignableFrom(value.getClass())) {
JsonArray array = (JsonArray) Json.array();
if (gInfo.isParameterArgumented()) {
converter = jsonConverrerMap.get(gInfo.getArgumentType());
JsonArray array = (JsonArray) Json.array();
Class<?> componentType = value.getClass().getComponentType();
converter = jsonConverrerMap.get(componentType);
代码示例来源:origin: com.tcdng.unify/unify-web
private JsonObject getJsonMenu(String menuId, List<MenuInfo> menuInfoList) throws UnifyException {
JsonObject menu = Json.object();
menu.add("menuId", menuId);
menu.add("popupId", "pop_" + menuId);
JsonArray items = Json.array();
for (int i = 0; i < menuInfoList.size(); i++) {
MenuInfo menuInfo = menuInfoList.get(i);
JsonObject item = Json.object();
item.add("id", menuId + i);
item.add("code", menuInfo.getCode());
item.add("multiple", menuInfo.isShowOnMultiple());
items.add(item);
}
menu.add("items", items);
return menu;
}
代码示例来源:origin: com.github.wnameless/json-flattener
private JsonValue findOrCreateJsonArray(JsonValue currentVal, String objKey,
Integer aryIdx) {
if (objKey != null) {
JsonObject jsonObj = currentVal.asObject();
if (jsonObj.get(objKey) == null) {
JsonValue ary = Json.array();
jsonObj.add(objKey, ary);
return ary;
}
return jsonObj.get(objKey);
} else { // aryIdx != null
JsonArray jsonAry = currentVal.asArray();
if (jsonAry.size() <= aryIdx || jsonAry.get(aryIdx).equals(Json.NULL)) {
JsonValue ary = Json.array();
assureJsonArraySize(jsonAry, aryIdx);
jsonAry.set(aryIdx, ary);
return ary;
}
return jsonAry.get(aryIdx);
}
}
代码示例来源:origin: mokies/ratelimitj
private JsonArray toJsonArray(RequestLimitRule rule) {
return Json.array().asArray()
.add(rule.getDurationSeconds())
.add(rule.getLimit())
.add(rule.getPrecision());
}
}
代码示例来源:origin: wnameless/json-flattener
private JsonValue findOrCreateJsonArray(JsonValue currentVal, String objKey,
Integer aryIdx) {
if (objKey != null) {
JsonObject jsonObj = currentVal.asObject();
if (jsonObj.get(objKey) == null) {
JsonValue ary = Json.array();
jsonObj.add(objKey, ary);
return ary;
}
return jsonObj.get(objKey);
} else { // aryIdx != null
JsonArray jsonAry = currentVal.asArray();
if (jsonAry.size() <= aryIdx || jsonAry.get(aryIdx).equals(Json.NULL)) {
JsonValue ary = Json.array();
assureJsonArraySize(jsonAry, aryIdx);
jsonAry.set(aryIdx, ary);
return ary;
}
return jsonAry.get(aryIdx);
}
}
代码示例来源:origin: dernasherbrezon/r2cloud
@Override
public ModelAndView doGet(IHTTPSession session) {
ModelAndView result = new ModelAndView();
JsonArray array = (JsonArray) Json.array();
for (Airplane cur : dao.getAirplanes()) {
JsonArray positions = (JsonArray) Json.array();
if (cur.getPositions() != null) {
for (Position curPosition : cur.getPositions()) {
positions.add(Json.object().add("lng", curPosition.getLongitude()).add("lat", curPosition.getLatitude()));
}
}
array.add(Json.object().add("icao24", cur.getIcao24()).add("positions", positions));
}
result.setData(array.toString());
return result;
}
代码示例来源:origin: com.github.wnameless/json-flattener
private JsonArray unflattenArray(JsonArray array) {
JsonArray unflattenArray = Json.array().asArray();
for (JsonValue value : array) {
if (value.isArray()) {
unflattenArray.add(unflattenArray(value.asArray()));
} else if (value.isObject()) {
unflattenArray.add(Json.parse(new JsonUnflattener(value.toString())
.withSeparator(separator).unflatten()));
} else {
unflattenArray.add(value);
}
}
return unflattenArray;
}
代码示例来源:origin: com.github.wnameless/json-flattener
if (isJsonArray(keyPart)) {
aryIdx = extractIndex(keyPart);
if (currentVal == null) currentVal = Json.array();
} else { // JSON object
objKey = extractKey(keyPart);
代码示例来源:origin: wnameless/json-flattener
if (isJsonArray(keyPart)) {
aryIdx = extractIndex(keyPart);
if (currentVal == null) currentVal = Json.array();
} else { // JSON object
objKey = extractKey(keyPart);
代码示例来源:origin: wnameless/json-flattener
private JsonArray unflattenArray(JsonArray array) {
JsonArray unflattenArray = Json.array().asArray();
for (JsonValue value : array) {
if (value.isArray()) {
unflattenArray.add(unflattenArray(value.asArray()));
} else if (value.isObject()) {
unflattenArray.add(Json.parse(new JsonUnflattener(value.toString())
.withSeparator(separator).unflatten()));
} else {
unflattenArray.add(value);
}
}
return unflattenArray;
}
代码示例来源:origin: wnameless/json-flattener
private void setUnflattenedValue(JsonObject flattened, String key,
JsonValue currentVal, String objKey, Integer aryIdx) {
JsonValue val = flattened.get(key);
if (objKey != null) {
if (val.isArray()) {
JsonValue jsonArray = Json.array();
for (JsonValue arrayVal : val.asArray()) {
jsonArray.asArray().add(
Json.parse(newJsonUnflattener(arrayVal.toString()).unflatten()));
}
currentVal.asObject().add(objKey, jsonArray);
} else {
currentVal.asObject().add(objKey, val);
}
} else { // aryIdx != null
assureJsonArraySize(currentVal.asArray(), aryIdx);
currentVal.asArray().set(aryIdx, val);
}
}
代码示例来源:origin: com.github.wnameless/json-flattener
private void setUnflattenedValue(JsonObject flattened, String key,
JsonValue currentVal, String objKey, Integer aryIdx) {
JsonValue val = flattened.get(key);
if (objKey != null) {
if (val.isArray()) {
JsonValue jsonArray = Json.array();
for (JsonValue arrayVal : val.asArray()) {
jsonArray.asArray().add(
Json.parse(newJsonUnflattener(arrayVal.toString()).unflatten()));
}
currentVal.asObject().add(objKey, jsonArray);
} else {
currentVal.asObject().add(objKey, val);
}
} else { // aryIdx != null
assureJsonArraySize(currentVal.asArray(), aryIdx);
currentVal.asArray().set(aryIdx, val);
}
}
代码示例来源:origin: fabienrenaud/java-json-benchmark
jso.add("longitude", u.longitude);
if (u.tags != null) {
com.eclipsesource.json.JsonArray jsarr = (com.eclipsesource.json.JsonArray) com.eclipsesource.json.Json.array();
for (String t : u.tags) {
jsarr.add(t);
com.eclipsesource.json.JsonArray jsarr = (com.eclipsesource.json.JsonArray) com.eclipsesource.json.Json.array();
for (Friend f : u.friends) {
com.eclipsesource.json.JsonObject jso0 = com.eclipsesource.json.Json.object();
代码示例来源:origin: com.tcdng.unify/unify-web
jsonPrm.add("pCtrlBase", tree.getControlImgIdBase());
jsonPrm.add("pLblBase", tree.getCaptionIdBase());
jsonPrm.add("pEventCode", Json.array(EVENT_CODES));
JsonArray menus = Json.array();
for (TreeItemCategoryInfo treeItemCategoryInfo : treeInfo.getTreeCategoryInfos()) {
if (treeItemCategoryInfo.isMenu()) {
JsonArray items = Json.array();
for (int i = 0; i < tree.getItemCount(); i++) {
TreeItemInfo<Object> treeItemInfo = tree.getTreeItemInfo(i);
内容来源于网络,如有侵权,请联系作者删除!