AnsweredAssumed Answered

How to parse an array(from alfresco) to json

Question asked by adrianp on Jul 22, 2009
Latest reply on Jul 24, 2009 by hyperation
Hi all,

I have a response from alfresco server like this  :

("0" => object (
                      "type" => "folder",
                      "depth" => "1",
                      "id" => "66b99eae-a1f5-4370-add2-36c509f534a0",
                      "title" => "FirmName",
                      "parent" => "Sites",
                      "parentID" => "cc1a7ea8-3c5d-47df-a917-c1b94e1efb6c",
                      "author" => "admin",
                      ),
       "1" => object (
                      "type" => "folder",
                      "depth" => "2",
                      "id" => "e6d1a350-f5d3-407b-81b6-a36ab1fae470",
                      "title" => "Projectname",
                      "parent" => "FirmName",
                      "parentID" => "66b99eae-a1f5-4370-add2-36c509f534a0",
                      "author" => "admin",
                      ),
       "2" => object (
                      "type" => "folder",
                      "depth" => "3",
                      "id" => "54479882-11db-4ef8-acbd-6d17dbedbc95",
                      "title" => "Drafts",
                      "parent" => "Projectname",
                      "parentID" => "e6d1a350-f5d3-407b-81b6-a36ab1fae470",
                      "author" => "admin",
                      ),
       "3" => object (
                      "type" => "document",
                      "folderId" => "54479882-11db-4ef8-acbd-6d17dbedbc95",
                      "id" => "a1c48eea-aaa9-4ff5-9966-4aa677c7b274",
                      "title" => "AUTHORS.txt",
                      ),
       "4" => object (
                      "type" => "document",
                      "folderId" => "54479882-11db-4ef8-acbd-6d17dbedbc95",
                      "id" => "f42c9d8a-8fcb-4ab0-adac-369ce4a34a0e",
                      "title" => "uninstall.log",
                      ),
       "5" => object (
                      "type" => "document",
                      "folderId" => "54479882-11db-4ef8-acbd-6d17dbedbc95",
                      "id" => "4c1341cc-baf9-45d9-8fa4-48d7034349f8",
                      "title" => "THANKS.txt",
                      ),
       "6" => object (
                      "type" => "folder",
                      "depth" => "2",
                      "id" => "04d05069-038e-4dba-98ac-06f697df75a9",
                      "title" => "COM",
                      "parent" => "FirmName",
                      "parentID" => "66b99eae-a1f5-4370-add2-36c509f534a0",
                      "author" => "admin",
                      ),
       "7" => object (
                      "type" => "folder",
                      "depth" => "3",
                      "id" => "caa66268-50fd-4027-a4da-caca038f4780",
                      "title" => "Drafts",
                      "parent" => "COM",
                      "parentID" => "04d05069-038e-4dba-98ac-06f697df75a9",
                      "author" => "admin",
                      ),
       "8" => object (
                      "type" => "document",
                      "folderId" => "caa66268-50fd-4027-a4da-caca038f4780",
                      "id" => "bd15b37a-cce5-41d5-a0c6-e553c82d1f9f",
                      "title" => "NEWS.txt",
                      ),
       "9" => object (
                      "type" => "folder",
                      "depth" => "3",
                      "id" => "a0a40a49-3969-4cae-be91-e88a34000579",
                      "title" => "Pending%20Review",
                      "parent" => "COM",
                      "parentID" => "04d05069-038e-4dba-98ac-06f697df75a9",
                      "author" => "admin",
                      ),
       "10" => object (
                       "type" => "document",
                       "folderId" => "a0a40a49-3969-4cae-be91-e88a34000579",
                       "id" => "3611b196-54e0-4cf6-bdcc-f39bd44133e5",
                       "title" => "notepad++.exe",
                       ),
       "11" => object (
                       "type" => "document",
                       "folderId" => "04d05069-038e-4dba-98ac-06f697df75a9",
                       "id" => "8ebab73c-8759-4678-9068-d842ac3acb25",
                       "title" => "NEWS.txt",
                       )
       )

Exists a parser for this kind of information? (this "information" represents the spaces tree from my alfresco).
I want to be parsed in a JSON. With this JSON i want to build a treePanel in EXTJS like this  :

var tree = new Ext.tree.TreePanel({
        width : 200,
        height : 400,
        animate:true,
        enableDD:false,
        loader: new Ext.tree.TreeLoader(),
        lines: true,
        renderTo: document.body,
        root: new Ext.tree.AsyncTreeNode({
            text: 'FirmName LCD',
            draggable:false,
            id:'source',
            children: json // ****** HERE IS THE JSON*****
        }),
        rootVisible:true
   });

Outcomes