[opencms-dev] JSON output
Андрей Диканский
andikk at mail.ru
Wed Feb 13 08:33:45 CET 2019
Thank you for your help! Now it works. Now in JSON output I have:
{"parts":["Title1","Title2","Title3"],
"Title1":"The title of the content: Title 3 (1/3)",
"Title3":"The title of the content: Title 1 (3/3)",
"Title2":"The title of the content: Title 2 (2/3)"}
Still I'd like another output something like
{"Titles": [
{ "Title":"The title of the content: Title 3 (1/3)"},
{"Title":"The title of the content: Title 1 (3/3)"},
{"Title":"The title of the content: Title 2 (2/3)"} ]
}
But it seems I can't achive it with <cms:jsonpart>. I guess I need custom java code for output like this.
>Среда, 13 февраля 2019, 9:55 +03:00 от 脸谱 <afeinet at 163.com>:
>
>
>There is another way you can try it:
>Jsonpart's element uses variables and does not use a fixed "Title".
><cms:jsonpart element="Title${info.resultIndex}"> ${content.value.Title} </cms:jsonpart>
>
>Have a look at the background to output a log like this:
>Duplicate key for JSON parts:
>
>Because from the output of your output, the parts part gets 3 data, but the List part is overwritten because it is the same KEY ("Title").
>In this case, your loop looks like this: Direction3.xml, Direction2.xml, Direction1.xml . . .
>
>
>--
>
>缘起法实不可思议也。
>
>在 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/40eefe17/attachment.htm>
More information about the opencms-dev
mailing list