本文整理匯總了Java中net.minidev.json.JSONArray.addAll方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.addAll方法的具體用法?Java JSONArray.addAll怎麽用?Java JSONArray.addAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minidev.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.addAll方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/json");
response.setStatus(HttpServletResponse.SC_OK);
String uri = request.getRequestURI();
int pathLen = request.getServletPath().length() + 1;
String taskIdString = uri.length() > pathLen ? uri.substring(pathLen) : "";
String[] taskIds = taskIdString.split(",");
JSONObject obj = new JSONObject();
for (String taskId : taskIds) {
Collection<String> tags = metadata.getTags(taskId);
JSONArray arr = new JSONArray();
arr.addAll(tags);
obj.put(taskId, arr);
}
Writer out = response.getWriter();
out.write(obj.toJSONString());
}
示例2: createToken
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private static String createToken(Info info) {
JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder();
claimsSetBuilder.subject(info.getUserName());
claimsSetBuilder.issueTime(new Date());
claimsSetBuilder.expirationTime(new Date(new Date().getTime() + 30 * 1000));
JSONArray roleValues = new JSONArray();
roleValues.addAll(info.getRoles());
Map<String, Object> roles = new HashMap<>();
roles.put("roles", roleValues);
claimsSetBuilder.claim("realm_access", roles);
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.RS512).type(JOSEObjectType.JWT).keyID(info.getApiKey()).build();
SignedJWT signedJWT = new SignedJWT(header, claimsSetBuilder.build());
System.out.println(claimsSetBuilder.build().toJSONObject().toString(JSONStyle.NO_COMPRESS));
try {
JWSSigner signer = new RSASSASigner((RSAKey) jwkSet.getKeyByKeyId(info.getApiKey()));
signedJWT.sign(signer);
} catch (JOSEException e) {
// Should not happen
e.printStackTrace();
}
return signedJWT.serialize();
}
示例3: createToken
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private static String createToken(Info info) {
JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder();
claimsSetBuilder.subject(info.getUserName());
claimsSetBuilder.issueTime(new Date());
claimsSetBuilder.expirationTime(new Date(new Date().getTime() + 60 * 1000));
JSONArray roleValues = new JSONArray();
roleValues.addAll(info.getRoles());
Map<String, Object> roles = new HashMap<>();
roles.put("roles", roleValues);
claimsSetBuilder.claim("realm_access", roles);
JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.HS256).type(JOSEObjectType.JWT).keyID(info.getApiKey()).build();
SignedJWT signedJWT = new SignedJWT(header, claimsSetBuilder.build());
try {
JWSSigner signer = new MACSigner(info.getHashKey());
signedJWT.sign(signer);
} catch (JOSEException e) {
// Should not happen
e.printStackTrace();
}
return signedJWT.serialize();
}
示例4: convertToArray
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private JSONArray convertToArray(List<String> elements) {
List<Map<String, Object>> result = new ArrayList<>(elements.size());
for (String str : elements) {
Map<String, Object> map = jsonStringToMap(str);
result.add(map);
}
JSONArray array = new JSONArray();
array.addAll(result);
return array;
}
示例5: createToken
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private static String createToken(String subject, RSAKey publicKey, String apiKey, List<String> roleNames) throws JOSEException {
// Create HMAC signer
JWSSigner signer = new MACSigner(apiKey);
// Prepare JWT with claims set
JWTClaimsSet.Builder claimsSetBuilder = new JWTClaimsSet.Builder();
claimsSetBuilder.subject(subject);
claimsSetBuilder.audience("Soteria RI"); // Your application
// To make token different each time. Counters the replay attacks.
claimsSetBuilder.issueTime(new Date());
claimsSetBuilder.expirationTime(new Date(new Date().getTime() + 60 * 1000));
JSONArray roleValues = new JSONArray();
roleValues.addAll(roleNames);
Map<String, Object> roles = new HashMap<>();
roles.put("roles", roleValues);
claimsSetBuilder.claim("realm_access", roles);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSetBuilder.build());
// Apply the HMAC
signedJWT.sign(signer);
// Create JWE object with signed JWT as payload
JWEObject jweObject = new JWEObject(
new JWEHeader.Builder(JWEAlgorithm.RSA_OAEP_256, EncryptionMethod.A128GCM)
.contentType("JWT") // required to signal nested JWT
.keyID(apiKey)
.build(),
new Payload(signedJWT));
JWEEncrypter encrypter = new RSAEncrypter(publicKey);
jweObject.encrypt(encrypter);
return jweObject.serialize();
}
示例6: jsonRepr
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
@Override
public JSONObject jsonRepr() {
JSONObject json = new JSONObject();
if (event.hasTaskId())
json.put("TaskID", this.taskID);
if (event.hasTimestamp())
json.put("Timestamp", event.getTimestamp());
if (event.hasHrt())
json.put("HRT", event.getHrt());
if (event.hasCycles())
json.put("Cycles", event.getCycles());
if (event.hasHost())
json.put("Host", event.getHost());
if (event.hasProcessId())
json.put("ProcessID", event.getProcessId());
if (event.hasProcessName())
json.put("ProcessName", event.getProcessName());
if (event.hasThreadId())
json.put("ThreadID", event.getThreadId());
if (event.hasThreadName())
json.put("ThreadName", event.getThreadName());
if (event.hasAgent())
json.put("Agent", event.getAgent());
if (event.hasSource())
json.put("Source", event.getSource());
if (event.hasLabel())
json.put("Label", event.getLabel());
for (int i = 0; i < event.getKeyCount(); i++) {
json.put(event.getKey(i), event.getValue(i));
}
if (event.getTagsCount() > 0) {
JSONArray tags = new JSONArray();
tags.addAll(event.getTagsList());
json.put("Tag", tags);
}
json.put("Title", "X-Trace Task");
if (event.hasTenantClass())
json.put("TenantClass", event.getTenantClass());
if (event.hasEventId())
json.put("EventID", Long.toString(event.getEventId()));
if (event.getParentEventIdCount() > 0) {
JSONArray parents = new JSONArray();
for (int i = 0; i < event.getParentEventIdCount(); i++) {
parents.add(Long.toString(event.getParentEventId(i)));
}
json.put("ParentEventID", parents);
}
return json;
}
示例7: loadObjectFromNBT
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
private Object loadObjectFromNBT(Object nbt) {
ReflectionObject reflection = new ReflectionObject(nbt);
switch (nbt.getClass().getSimpleName()) {
case "NBTTagList":
JSONObject tagList = new JSONObject();
JSONArray tagListArray = new JSONArray();
List<?> list = (List<?>) reflection.getField("list").getValue().getObject();
for (Object base : list) {
tagListArray.add(loadObjectFromNBT(base));
}
tagList.put("nbtTagList", tagListArray);
return tagList;
case "NBTTagCompound":
JSONObject compoundObject = new JSONObject();
Set<?> keys = (Set<?>) reflection.getMethod("c").invoke().getObject();
ReflectionMethod get = reflection.getMethodByClasses("get", String.class);
for (Object key : keys) {
compoundObject.put((String) key, loadObjectFromNBT(get.invoke(key).getObject()));
}
return compoundObject;
case "NBTTagIntArray":
JSONArray tagIntArray = new JSONArray();
tagIntArray.addAll(Arrays.asList((int[]) reflection.getMethod("c").invoke().getObject()));
JSONObject intArray = new JSONObject();
intArray.put("nbtTagIntArray", tagIntArray);
return intArray;
case "NBTTagByteArray":
JSONArray tagByteArray = new JSONArray();
tagByteArray.addAll(Arrays.asList((byte[]) reflection.getMethod("c").invoke().getObject()));
JSONObject byteArray = new JSONObject();
byteArray.put("nbtTagByteArray", tagByteArray);
return byteArray;
case "NBTTagString":
return reflection.getMethod("a_").invoke().getObject();
case "NBTTagDouble":
return reflection.getMethod("g").invoke().getObject();
case "NBTTagFloat":
return reflection.getMethod("h").invoke().getObject();
case "NBTTagLong":
return reflection.getMethod("c").invoke().getObject();
case "NBTTagInt":
return reflection.getMethod("d").invoke().getObject();
case "NBTTagShort":
return reflection.getMethod("e").invoke().getObject();
case "NBTTagByte":
return reflection.getMethod("f").invoke().getObject();
default:
// hmm
return nbt.toString();
}
}
示例8: build
import net.minidev.json.JSONArray; //導入方法依賴的package包/類
public JSONArray build() {
JSONArray array = new JSONArray();
array.addAll(jsonList);
return array;
}