当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.addAll方法代码示例

本文整理汇总了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());
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:20,代码来源:WebServer.java

示例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();
}
 
开发者ID:atbashEE,项目名称:jsr375-extensions,代码行数:32,代码来源:TokenGenerator.java

示例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();
}
 
开发者ID:rdebusscher,项目名称:soteria-jwt,代码行数:30,代码来源:JwsMain.java

示例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;
}
 
开发者ID:fhoeben,项目名称:hsac-fitnesse-fixtures,代码行数:11,代码来源:JsonHelper.java

示例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();

    }
 
开发者ID:rdebusscher,项目名称:soteria-jwt,代码行数:43,代码来源:JWEMain.java

示例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;
}
 
开发者ID:brownsys,项目名称:tracing-framework,代码行数:52,代码来源:ReportImpl.java

示例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();
    }
}
 
开发者ID:BurnGames,项目名称:BGDCore,代码行数:52,代码来源:v1_7_R1.java

示例8: build

import net.minidev.json.JSONArray; //导入方法依赖的package包/类
public JSONArray build() {
    JSONArray array = new JSONArray();
    array.addAll(jsonList);
    return array;
}
 
开发者ID:aemreunal,项目名称:iBeaconServer,代码行数:6,代码来源:JsonArrayBuilder.java


注:本文中的net.minidev.json.JSONArray.addAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。