當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNode.iterator方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.JsonNode.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.iterator方法的具體用法?Java JsonNode.iterator怎麽用?Java JsonNode.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.iterator方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: treeTraversalSolution

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public void treeTraversalSolution() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        // use the ObjectMapper to read the json string and create a tree
        JsonNode node = mapper.readTree(new File("Persons.json"));
        Iterator<String> fieldNames = node.fieldNames();
        while (fieldNames.hasNext()) {
            JsonNode personsNode = node.get("persons");
            Iterator<JsonNode> elements = personsNode.iterator();
            while (elements.hasNext()) {
                JsonNode element = elements.next();
                JsonNodeType nodeType = element.getNodeType();
                
                if (nodeType == JsonNodeType.STRING) {
                    out.println("Group: " + element.textValue());
                }

                if (nodeType == JsonNodeType.ARRAY) {
                    Iterator<JsonNode> fields = element.iterator();
                    while (fields.hasNext()) {
                        parsePerson(fields.next());
                    }
                }
            }
            fieldNames.next();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:31,代碼來源:JSONExamples.java

示例2: getAliases

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
default Set<String> getAliases() {
    if (this instanceof Annotable) {
        JsonNode node = ((Annotable) this).getAnnotations().get(ALIASES);
        if (node == null) {
            node = ((Annotable) this).getAnnotations().get(ALIAS);
        }
        Set<String> set = Sets.newHashSet();
        if (node == null) {
            return set;
        } else {
            if (node.isTextual()) {
                set.add(node.textValue());
            } else if (node.isArray()) {
                Iterator<JsonNode> it = node.iterator();
                while (it.hasNext()) {
                    JsonNode val = it.next();
                    Preconditions.checkArgument(val.isTextual());
                    set.add(val.textValue());
                }
            }
            return set;
        }
    } else {
        throw new IllegalArgumentException("Not annotable, must override!");
    }
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:27,代碼來源:Aliases.java

示例3: getCores

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Get target cores via CoreAdminAPI.
 *
 * @param httpSolrClient
 * @return
 */
public static List<String> getCores(HttpSolrClient httpSolrClient) throws SolrServerException, IOException {
    List<String> cores = new ArrayList<>();

    NoOpResponseParser responseParser = new NoOpResponseParser();
    responseParser.setWriterType("json");

    httpSolrClient.setParser(responseParser);

    CoreAdminRequest coreAdminRequest = new CoreAdminRequest();
    coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
    coreAdminRequest.setIndexInfoNeeded(false);

    NamedList<Object> coreAdminResponse = httpSolrClient.request(coreAdminRequest);

    JsonNode statusJsonNode = om.readTree((String) coreAdminResponse.get("response")).get("status");

    for (Iterator<JsonNode> i = statusJsonNode.iterator(); i.hasNext(); ) {
        String core = i.next().get("name").textValue();
        if (!cores.contains(core)) {
            cores.add(core);
        }
    }

    return cores;
}
 
開發者ID:mosuka,項目名稱:solr-exporter,代碼行數:32,代碼來源:SolrCollector.java

示例4: getCollections

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Get target cores via CollectionsAPI.
 *
 * @param cloudSolrClient
 * @return
 */
public static List<String> getCollections(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
    List<String> collections = new ArrayList<>();

    NoOpResponseParser responseParser = new NoOpResponseParser();
    responseParser.setWriterType("json");

    cloudSolrClient.setParser(responseParser);

    CollectionAdminRequest collectionAdminRequest = new CollectionAdminRequest.List();

    NamedList<Object> collectionAdminResponse = cloudSolrClient.request(collectionAdminRequest);

    JsonNode collectionsJsonNode = om.readTree((String) collectionAdminResponse.get("response")).get("collections");

    for (Iterator<JsonNode> i = collectionsJsonNode.iterator(); i.hasNext(); ) {
        String collection = i.next().textValue();
        if (!collections.contains(collection)) {
            collections.add(collection);
        }
    }

    return collections;
}
 
開發者ID:mosuka,項目名稱:solr-exporter,代碼行數:30,代碼來源:SolrCollector.java

示例5: nodeReferences

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
public Stream<NodeReference> nodeReferences() {
    final String searchUrl = url + AlfredConstants.SEARCH;
    logger.debug("Search url: {}", searchUrl);
    logger.debug("Recherche: {}", query != null ? query.getBody().toString() : "NULL");
    final ResponseEntity<ObjectNode> objectNodeResponseEntity =
            restTemplate.postForEntity(searchUrl, query.getBody(), ObjectNode.class);
    final AlfredPath alfredPath;
    if (objectNodeResponseEntity.getStatusCode().equals(HttpStatus.OK)) {
        final ObjectNode bodyResponse = objectNodeResponseEntity.getBody();
        final JsonNode nodeRefs = bodyResponse.get("noderefs");
        final Iterator<JsonNode> iterator = nodeRefs.iterator();
        Stream<JsonNode> jsonStream = StreamSupport.stream(Spliterators.spliterator(iterator, nodeRefs.size(), Spliterator.ORDERED)
                , true);
        return jsonStream
                .map(JsonNode::asText)
                .map(nodeReferenceBuilder::nodeReference);
    } else {
        logger.warn("Problème pour retrouver les informations: {}", objectNodeResponseEntity.getStatusCode());
    }
    return Stream.empty();
}
 
開發者ID:avdyk,項目名稱:be.liege.cti.ged,代碼行數:23,代碼來源:AlfredSearchImpl.java

示例6: node2list

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * 
 * jsonnode 轉list對象<br>
 *
 * @param jsonNode
 * @param clazz
 * @return
 * List<T>
 * @Author fanyaowu
 * @data 2014年7月19日
 * @exception 
 * @version
 *
 */
public static <T> List<T> node2list(JsonNode jsonNode, Class<T> clazz)
{
	if (null == jsonNode || !jsonNode.isArray())
	{
		return null;
	}

	List<T> tList = new ArrayList<>();

	for (Iterator<JsonNode> nodeIt = jsonNode.iterator(); nodeIt.hasNext();)
	{
		JsonNode node = nodeIt.next();
		T t = node2obj(node, clazz);

		tList.add(t);
	}

	return tList;
}
 
開發者ID:marlonwang,項目名稱:raven,代碼行數:34,代碼來源:JsonUtils.java

示例7: parseIpArrayToPrefix

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/** Ip address parser decoder.*/
public ExtPrefix.Builder parseIpArrayToPrefix(JsonNode array) {

    ExtPrefix.Builder resultBuilder = new DefaultExtPrefix.Builder();
    String ip;
    IpPrefix prefix;
    IpAddress ipAddr;

    Iterator<JsonNode> itr =  array.iterator();
    while (itr.hasNext()) {
        ip = itr.next().asText();
        ipAddr = IpAddress.valueOf(ip);
        prefix = IpPrefix.valueOf(ipAddr, 32);
        resultBuilder.setPrefix(prefix);
    }

    return resultBuilder;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:DecodeBgpFlowExtnCodecHelper.java

示例8: parsePerson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public void parsePerson(JsonNode node) {
    Iterator<JsonNode> fields = node.iterator();
    while(fields.hasNext()) {
        JsonNode subNode = fields.next();
        out.println(subNode.asText());
    }
}
 
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:8,代碼來源:JSONExamples.java

示例9: parseArgs

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * 解析 jsonNode 獲取參數字符串
 * @param argNodes
 * @return
 */
private String parseArgs(JsonNode argNodes){
    StringBuilder args = new StringBuilder();
    if ("ARRAY".equals(argNodes.getNodeType().name())){
        Iterator<JsonNode> iterator = argNodes.iterator();
        while (iterator.hasNext()){
            args = args.append(iterator.next().asText());
        }
    }
    return args.toString();
}
 
開發者ID:flyer88,項目名稱:EasyJsBridge,代碼行數:16,代碼來源:JsBridge.java

示例10: extractUserProfile

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
protected CasOAuthWrapperProfile extractUserProfile(final String body) throws HttpAction {
    final CasOAuthWrapperProfile userProfile = new CasOAuthWrapperProfile();
    JsonNode json = JsonHelper.getFirstNode(body);
    if (json != null) {
        userProfile.setId(JsonHelper.getElement(json, "id"));
        json = json.get("attributes");
        if (json != null) {
            // CAS <= v4.2
            if (json instanceof ArrayNode) {
                final Iterator<JsonNode> nodes = json.iterator();
                while (nodes.hasNext()) {
                    json = nodes.next();
                    final String attribute = json.fieldNames().next();
                    userProfile.addAttribute(attribute, JsonHelper.getElement(json, attribute));
                }
                // CAS v5
            } else if (json instanceof ObjectNode) {
                final Iterator<String> keys = json.fieldNames();
                while (keys.hasNext()) {
                    final String key = keys.next();
                    userProfile.addAttribute(key, JsonHelper.getElement(json, key));
                }
            }
        }
    }
    return userProfile;
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:29,代碼來源:CasOAuthWrapperClient.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。