本文整理汇总了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();
}
}
示例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!");
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}