Results 1 to 3 of 3

Thread: Problems parsing json

  1. #1
    Join Date
    Jan 2010
    Location
    Scotland
    Posts
    27

    Default 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. #2
    Join Date
    Dec 2008
    Posts
    3

    Default

    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ú.

  3. #3
    Join Date
    May 2010
    Posts
    1

    Smile

    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 at 08:32 AM.
    P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •