2017-09-12 48 views
1

在我的JCR節點我有鑰匙subpage,並持有String[]類型的值:如何訪問存儲在jcr節點中的字符串數組?

{"title":"some title1", "url":"some url1"} 
{"title":"some title2", "url":"some url2"} 
{"title":"some title3", "url":"some url3"} 
{"title":"some title4", "url":"some url4"} 

我怎麼能訪問它在Java?

我想:

ValueMap contentValueMap = resource.getValueMap(); 

String subpages = contentValueMap.get("subpage", String.class); 

System.out.println(subpages); 

,但只打印第一個字符串:

{"title":"some title1", "url":"some url1"} 

我怎麼能達到他們的休息嗎?

+0

謝謝,我可以使用它,但我不知道如何繼續,或者更確切地說 - 如何在我的情況下有所幫助:( – randomuser1

回答

4

這應該與工作

String[] subpages = contentValueMap.get("subpage", String[].class); 
+0

當然,它的工作原理如何我以前沒有嘗試過:謝啦! – randomuser1

3

由於AWD提到

String[] subPages = contentValueMap.get("subpage", String[].class); 

作品,是推薦的解決方案。這是在Sling層訪問數據。只要您需要深入瞭解並訪問JCR層,代碼將如下所示

Node node=resource.adaptTo(Node.class); 
Value[] subPages = node.getProperty("subpage").getValues(); 

這將對節點級操作有所幫助。但建議在Sling或AEM的更高層工作。

相關問題