AEM-如何以JSON格式返回页面信息

AEM-如何以JSON格式返回页面信息,aem,Aem,我需要以JSON格式显示给定路径中所有子页面和子页面的标题和名称。请提供实施方案。首先您必须自己尝试,然后您需要寻求帮助,而不是完整的解决方案!无论如何,下面有两个解决方案 根据此处,您可以实现JSON格式的页面信息: package com.adobe.example; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Properties; import or

我需要以JSON格式显示给定路径中所有子页面和子页面的标题和名称。请提供实施方案。

首先您必须自己尝试,然后您需要寻求帮助,而不是完整的解决方案!无论如何,下面有两个解决方案

根据此处,您可以实现JSON格式的页面信息:

package com.adobe.example;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageInfoProvider;

@Component(metatype = false)
@Properties({
    @Property(name="service.description", value="Returns the public URL of a resource.")
})
@Service
public class PageUrlInfoProvider implements PageInfoProvider {


    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
    private com.day.cq.commons.Externalizer externalizer;

    private String fetchExternalUrl(ResourceResolver rr, String path) {
        return externalizer.publishLink(rr, path);
    }

    public void updatePageInfo(SlingHttpServletRequest request, JSONObject info, Resource resource)
            throws JSONException {

        Page page = resource.adaptTo(Page.class);
        JSONObject urlinfo = new JSONObject();
        urlinfo.put("publishURL", fetchExternalUrl(null,page.getPath()));
        info.put("URLs",urlinfo);
    }
}

或者您可以尝试此解决方案,请参考下面的链接,该链接可能很有用:

除上述解决方案外,您还可以使用递归级别以JSON格式获取数据,例如/content/we retail/language masters/en.{placeholder}.JSON

将占位符替换为要打印的节点级别,并在需要时返回JSON

要了解有关以不同格式渲染数据的更多信息,
请参阅:

到目前为止您尝试了什么?你在哪里卡住了?编程问题也是如此。“请提供实现”不是一个问题,而是一个编码请求。