本文整理匯總了Java中org.codehaus.jackson.JsonNode.getFieldNames方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.getFieldNames方法的具體用法?Java JsonNode.getFieldNames怎麽用?Java JsonNode.getFieldNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonNode
的用法示例。
在下文中一共展示了JsonNode.getFieldNames方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMessages
import org.codehaus.jackson.JsonNode; //導入方法依賴的package包/類
/**
* Retrieves the list of mail messages currently stored
*
* @return the list of messages, possibly empty
* @throws ClientException in case of any errors
*/
public List<EmailMessage> getMessages() throws ClientException {
List<EmailMessage> emails = new ArrayList<>();
try {
SlingHttpResponse response = doGet(EMAIL_SERVLET_PATH + "/messages", SC_OK);
JsonNode messages = mapper.readTree(response.getContent());
for ( JsonNode emailNode : messages.get("messages") ) {
EmailMessage msg = new EmailMessage(emailNode.get(PN_CONTENT).getTextValue());
Iterator<String> fieldNames = emailNode.getFieldNames();
while ( fieldNames.hasNext() ) {
String fieldName = fieldNames.next();
if ( fieldName.equals(PN_CONTENT) ) {
continue;
}
msg.addHeader(fieldName, emailNode.get(fieldName).getTextValue());
}
emails.add(msg);
}
} catch (IOException e) {
throw new ClientException("Failed retrieving email messages", e);
}
return emails;
}
示例2: getConfiguration
import org.codehaus.jackson.JsonNode; //導入方法依賴的package包/類
/**
* Returns a map of all properties set for the config referenced by the PID, where the map keys
* are the property names.
*
* @param pid the pid of the configuration
* @param expectedStatus list of accepted statuses of the response
* @return the properties as a map
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public Map<String, Object> getConfiguration(String pid, int... expectedStatus) throws ClientException {
// make the request
SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + pid, null);
// check the returned status
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
// get the JSON node
JsonNode rootNode = JsonUtils.getJsonNodeFromString(resp.getContent());
// go through the params
Map<String, Object> props = new HashMap<String, Object>();
if(rootNode.get("properties") == null)
return props;
JsonNode properties = rootNode.get("properties");
for(Iterator<String> it = properties.getFieldNames(); it.hasNext();) {
String propName = it.next();
JsonNode value = properties.get(propName).get("value");
if(value != null) {
props.put(propName, value.getValueAsText());
continue;
}
value = properties.get(propName).get("values");
if(value != null) {
Iterator<JsonNode> iter = value.getElements();
List<String> list = new ArrayList<String>();
while(iter.hasNext()) {
list.add(iter.next().getValueAsText());
}
props.put(propName, list.toArray(new String[list.size()]));
}
}
return props;
}