Announcement Announcement Module
Collapse
No announcement yet.
Problems parsing json Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems parsing json

    Dear all, I have created a webscript that passes back json, example as follows...

    Code:
    {
        "sitetree" : {
            "node" : {
                "name" : "test.html",
                "nodeRef" : "workspace://SpacesStore/a86f1bad-08cc-426c-a5ea-79d3f2e4ed8e",
                "description" : "Test file",
                "icon" : "/images/filetypes/html.gif" 
            } ,
            "node" : {
                "name" : "website1",
                "nodeRef" : "workspace://SpacesStore/f0e810d1-a405-4e14-a654-d116c25d581e",
                "description" : "",
                "icon" : "/images/icons/space-icon-default-16.gif" ,
                "node" : {
                    "name" : "website1.html",
                    "nodeRef" : "workspace://SpacesStore/410d7d3b-109f-4dac-9164-df50891f3e9d",
                    "description" : "",
                    "icon" : "/images/filetypes/html.gif" 
                } 
            } 
        } 
    }
    I call that from within my springsurf file using the following...

    Code:
    // get a connector to the Alfresco repository endpoint
    var connector = remote.connect("alfresco"); 
    var result = connector.call("/alfrescocms/getsitetree");
    model.sitetree = eval( '(' + result + ')' );
    And then try to parse it as follows...

    Code:
    <#macro parseChild objectModel>
    	<#list objectModel.node as child>
    		<li><img src="${child.node.icon}"><a href="${child.node.nodeRef}">${child.node.name}</a></li>
    	</#list>
    </#macro>
    <h3><a href="#">Site Tree</a></h3>
    <div>
    	<ul>
    		<@parseChild sitetree.sitetree />
    	</ul>
    </div>
    But I keep getting the error
    Code:
    freemarker.template.TemplateException - Expected collection or sequence. objectModel.node evaluated instead to freemarker.template.SimpleHash on line 3, column 16 in webscripts/getsitetree/getsitetree.get.html.ftl.
    Can anyone offer any insight into what I'm doing wrong. The JSON that is passed back seems to validate without any problem. Perhaps I'm misunderstanding what is possible with Freemarker?

  • #2
    It should be

    Code:
    <#list objectModel as child>
    to list the nodes, as objectModel here is the list with many children.

    Have a nice day,
    Tanausú.

    Comment


    • #3
      I am having a similar trouble as the OP. Many thanks for the tip Tanausú. I would give it a try


      Rosie Jonesronald Cruzag
      Last edited by rosiejons5; Oct 3rd, 2010, 08:32 AM.

      Comment

      Working...
      X