How to loop json data in my test endpoint?
Hello:
I want to know how to loop json data inside the freemarker list section.
I got json data from rest api in the endpoint,but when I try to get the properties of every category inside the list section I always got freemarker syntax error.
I want to get the every category's id/title/view_href,etc.But I do not know how to get them and how to inject these data items into the data property as json format data for return.
The following is my code in the endpoint.
<#compress>
<#assign messageId = http.request.parameters.name.get("id","")?string />
<#if messageId?length gt 0>
<#attempt>
<#assign top = rest("/categories/top?&restapi.format_detail=full_list_element&restapi.response_style=view&restapi.response_format=json").category />
<#list top.categories as cat>
${cat.id} <#-- this code looks cause freemarker syntax error,maybe I made some mistake with it. -->
</#list>
<#assign ret = '{"response":{"status":"success", "data":{"id":${top.id}}}}'>
<#recover>
<#assign ret = '{"response":{"status":"error","error":{"code":100,"message":"Error making rest call with message id ${messageId}."}}}'>
</#attempt>
${ret}
<#else>
<#assign ret = '{"response":{"status":"error","error":{"code":100,"message":"Missing required parameter \"id\"."}}}'>
${ret}
</#if>
</#compress>
Any help would be appreciated.