AEM:从 java 中的节点读取值,该值是多字段的值
AEM: reading a value from a node in java which is value of a multifield
我正在阅读java中的一组节点。每个节点属于一个国家。每个节点都有 属性 "country" 并且对于像美国这样的一些国家也有 "states" 属性 节点。 "states" 是多字段的一部分,因此每个项目都有一个状态,它们都在一个节点中,如下所示:
country = "US"
, states = [{"statename":"District of Columbia"}, {"statename":"Rhode Island"},{"statename":"South Dakota"}]
我想通过像这样的 servlet 调用将它们填充为页面中的 json:
http://localhost:4502/bin/utilservlet.json
{
country: "India"
{
statename:"Delhi",
statename:"Punjab",
statename:"Haryana"
}
}
{
country: "Turkey"
}
以下是我的代码:
while (nodeItr.hasNext()) {
Node cNode = nodeItr.nextNode();
if (cNode.hasProperty("country")) {
JSONObject jsonData = new JSONObject();
jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
jsonArray.put(jsonData);
if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());
发生以下情况:
1. 我得到了所有国家列表,除了第一个国家 属性 退出的国家。
2. 没有显示其他有statelist的国家。
我做错了什么?
尝试以下操作:
if (cNode.hasProperty("states")) {
Property statesProperty = cNode.getProperty("states");
if (statesProperty.isMultiple()) {
Value[] statesValues = states.getValues();
for (Value stateValue : stateValues) {
LOG.info(stateValue.getString());
}
}
}
我正在阅读java中的一组节点。每个节点属于一个国家。每个节点都有 属性 "country" 并且对于像美国这样的一些国家也有 "states" 属性 节点。 "states" 是多字段的一部分,因此每个项目都有一个状态,它们都在一个节点中,如下所示:
country = "US"
, states = [{"statename":"District of Columbia"}, {"statename":"Rhode Island"},{"statename":"South Dakota"}]
我想通过像这样的 servlet 调用将它们填充为页面中的 json:
http://localhost:4502/bin/utilservlet.json
{
country: "India"
{
statename:"Delhi",
statename:"Punjab",
statename:"Haryana"
}
}
{
country: "Turkey"
}
以下是我的代码:
while (nodeItr.hasNext()) {
Node cNode = nodeItr.nextNode();
if (cNode.hasProperty("country")) {
JSONObject jsonData = new JSONObject();
jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
jsonArray.put(jsonData);
if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());
发生以下情况: 1. 我得到了所有国家列表,除了第一个国家 属性 退出的国家。 2. 没有显示其他有statelist的国家。
我做错了什么?
尝试以下操作:
if (cNode.hasProperty("states")) {
Property statesProperty = cNode.getProperty("states");
if (statesProperty.isMultiple()) {
Value[] statesValues = states.getValues();
for (Value stateValue : stateValues) {
LOG.info(stateValue.getString());
}
}
}