[opencms-dev] JSON array from a list
    Paoletti Corrado 
    c.paoletti at fineco.it
       
    Thu Dec 23 13:15:13 CET 2021
    
    
  
FinecoBank S.p.A. - Internal Use Only
Hi,
my target is to generate a JSON response from a list of users.
With one user <cms:jsonpart generates a correct JSON but when I use it inside a <c:forEach I obtain only the last user so I deduce that <cms:jsonpart is not sufficient.
Searching examples and documentation I find that I could use a combination of JSONArray and JSONObject and these objects are defined in cms taglibrary (https://documentation.opencms.org/javadoc/tld/cms/jsonarray.html)
So, I have write <cms:jsonarray but I have:
No tag "jsonarray" defined in tag library imported with prefix "cms"
Someone could suggest me the right way to follow to have a JSON array like this:
[
{"name":"giulio", "surname":"cesare"},
{"name":"dante", "surname":"alighieri"},
]
Another approach is to use Java (I am not Java programmer) so I have wrote:
<%@page import="org.opencms.json.JSONException, org.opencms.json.JSONArray, org.opencms.json.JSONObject"%>
<%
    JSONObject user = new JSONObject();
    try {
        user.put("name", "giulio");
        user.put("surname", "cesare");
    } catch (JSONException e) {
    }
    JSONArray userList = new JSONArray();
    userList.put(user);
        System.out.println( userList );
%>
but nothing happens.
Kind regards and Happy Christmas.
Corrado
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opencms.org/pipermail/opencms-dev/attachments/20211223/bb307db5/attachment.htm>
    
    
More information about the opencms-dev
mailing list