[opencms-dev] JSON output

脸谱 afeinet at 163.com
Wed Feb 13 08:01:55 CET 2019



I checked the implementation code of JsonPart, the “parts” part uses Array, the “List” part uses Map, so there will be duplicate values in the “parts” part, and the duplicate keys of the "List" part will be overwritten. .


             JSONArray keys = new JSONArray();
             JSONObject output = new JSONObject();


             For (CmsJsonPart part : parts) {
                 If (output.has(part.getKey())) {
                     LOG.warn("Duplicate key for JSON parts: " + part.getKey());
                 }
                 Keys.put(part.getKey());
                 Output.put(part.getKey(), part.getValue());
             }
             Output.put(KEY_PARTS, keys);


Maybe this is a bug, you can go to an issue. .




--



缘起法实不可思议也。

在 2019-02-13 13:41:55,"Андрей Диканский" <andikk at mail.ru> 写道:
I tried it. I still have "wrong" JSON output:


{"parts":["Title","Title","Title"],"Title":"Title 1"}

It seems that <cms:jsonpart> takes only the last one content element for output.


Среда, 13 февраля 2019, 9:31 +03:00 от 脸谱 <afeinet at 163.com>:


Hi, I have not used the jsonpart tag, but I suggest you use the following code to try to see what the output is.


<cms:contentload collector="allInFolder" param="/service/1/Direction-%(number).xml|Direction" preload="true">

  <cms:contentinfo var="info" />
  <c:if test="${info.resultSize > 0}">
  <cms:contentload>
      <%--  This is itself a loop call. It is not sure which part is decided. --%>
      <cms:contentaccess var="content" /> <%-- This content will change with the loop, so it might be yours Direction1.xml, Direction2.xml, Direction3.xml . . . --%>
      <cms:jsonpart element="Title">  ${content.value.Title}  </cms:jsonpart>
   </cms:contentload>
  </c:if>
 </cms:contentload> 










 

_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev






--
Andrew Dikansky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20190213/4f4cc5fe/attachment.htm>


More information about the opencms-dev mailing list