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


Java JsonNode.withArray方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.withArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.withArray方法的具体用法?Java JsonNode.withArray怎么用?Java JsonNode.withArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.withArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResultListFromJson

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private ArrayList<JsonNode> getResultListFromJson(JsonNode response) {

        ArrayList<JsonNode> resultList = new ArrayList<>();

        // ignore case when parsing items array
        String itemsKey = response.has("Items") ? "Items" : "items";

        for (JsonNode item : response.withArray(itemsKey)) {
            try {
                resultList.add(item);
            } catch (Exception e) {
                log.error("Could not parse data from Key Value Storage");
                throw new CompletionException(
                    new ExternalDependencyException(
                        "Could not parse data from Key Value Storage"));
            }
        }

        return resultList;
    }
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:21,代码来源:Rules.java

示例2: setDatabaseFieldProperties

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void setDatabaseFieldProperties(String dbName,String field_name, String propName, ObjectNode objNode ) throws IOException{
		InputStream jsonstream=null;
		try{
			DefaultHttpClient client = new DefaultHttpClient();
			client.getCredentialsProvider().setCredentials(
					new AuthScope(host, 8002),
					new UsernamePasswordCredentials("admin", "admin"));
			HttpGet getrequest = new HttpGet("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
			HttpResponse response1 = client.execute(getrequest);
			jsonstream =response1.getEntity().getContent();
			ObjectMapper mapper = new ObjectMapper();
			JsonNode jnode= mapper.readTree(jsonstream);
			if(!jnode.isNull()&& jnode.has("field")){
				JsonNode  fieldNode = jnode.withArray("field");
				Iterator<JsonNode> fnode = fieldNode.elements();
				while(fnode.hasNext()) {
					JsonNode fnchild =fnode.next();
					if((fnchild.path("field-name").asText()).equals(field_name)){
						//            			System.out.println("Hurray" +fnchild.has(propName));
						if(!fnchild.has(propName)){
							((ObjectNode)fnchild).putArray(propName).addAll(objNode.withArray(propName));
//							System.out.println("Adding child array include node" + jnode.toString());
						}
						else{
							JsonNode member = fnchild.withArray(propName);
							((ArrayNode)member).addAll(objNode.withArray(propName));
						}

					}
				}

				HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
				put.addHeader("Content-type", "application/json");
				put.setEntity(new StringEntity(jnode.toString()));

				HttpResponse response2 = client.execute(put);
				HttpEntity respEntity = response2.getEntity();
				if(respEntity != null){
					String content =  EntityUtils.toString(respEntity);
					System.out.println(content);
				}
			}
			else{
				System.out.println("REST call for database properties returned NULL \n"+jnode.toString()+"\n"+ response1.getStatusLine().getStatusCode());
			}
		}catch (Exception e) {
			// writing error to Log
			e.printStackTrace();
		}
		finally{
			if(jsonstream == null){}
			else{
				jsonstream.close();
			}
		}
	}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:57,代码来源:ConnectedRESTQA.java


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